0
저는 Asp .Net MVC 및 C#을 아직 사용하지 않았습니다. 특정 작업을 수행하는 방법을 배우는 중 경험이 있으며 단추를 내보기로로드하는 데 문제가 있습니다. .NET MVC에서 일반적으로하는 것처럼 이벤트 리스너가 필요 없다는 것을 알았 기 때문에 @ Ajax.ActionLink를 사용했습니다. 그러나 내 단추를 클릭하면 내보기가로드되지 않습니다. 나는 이유를 알 수 없다? 단추가 내보기를로드 할 수 없습니다.ASP .NET MVC에서 이미지 업로드를 jpg로 제한
다음은 내가 수행 한 작업입니다. 내 공유 폴더에는 버튼이 포함 된 레이아웃 페이지가 있습니다.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HexaPod.Controllers
{
public class TestImageExtensionController : Controller
{
// For multiple file select
[HttpPost]
public ActionResult Create(List<HttpPostedFileBase> image)
{
if (image != null)
{
foreach (var item in image)
{
string filePath = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(item.FileName));
item.SaveAs(filePath);
}
}
return PartialView("TestImageExtension");
}
}
}
모델 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HexaPod.Models
{
public partial class ImageUpload {
public int ID { get; set;}
public string ImagePath {get; set;}
}
}
보기 :
나는 다음과 컨트롤러를 삽입 한 내 컨트롤러 폴더에서<li>@Ajax.ActionLink("Res-TestImageExtension","TestImageExtension","TestImageExtension","",App.ViewOptions.appAjaxOptions,App.ViewOptions.blueButtonHtmlAttributes)</li>
:이 버튼을 삽입
@model HexaPod.Models.ImageUpload
@{
ViewBag.Title = "Image Upload";
}
@*
*@
@using (Html.BeginForm("Create", "Profile", FormMethod.Post, new { enctype =
"multipart/form-data", id = "frm_profile" }))
{
@Html.LabelFor(model => model.ImagePath)
@Html.TextBoxFor(model => model.ImagePath, new { type = "file", accept = "image/jpeg, image/jpg"}) @Html.ValidationMessageFor(model => model.ImagePath)
// for multiple file select
@Html.TextBoxFor(model => model.ImagePath, new { type = "file", accept = "image/jpeg, image/jpg", multiple = "multiple" })
}