모델 만들기 페이지를 만들려고합니다. 나는 asp.net mvc C# 사용하고 있습니다. 내 프로젝트에서는 책이있는 라이브러리 응용 프로그램을 만들려고하고 있으며 그림이있는 응용 프로그램에서 책을 추가 할 수 있습니다. 그래서,파일을 업로드 할 수 없습니다. ASP.NET MVC
[HttpPost]
public ActionResult Create([Bind(Exclude = "id,bringBack,borrower,isBorrowed")]Book bookToCreate, HttpPostedFileBase picture1)
{
try
{
if (picture1.ContentLength > 0)
{
var fileName = Path.GetFileName(picture1.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/pictures"), fileName);
picture1.SaveAs(path);
}
// TODO: Add insert logic here
_entities.AddToLibrary(bookToCreate);
_entities.SaveChanges();
return RedirectToAction("ListBooks");
}
catch
{
return View();
}
}
을 같은 컨트롤러를 만들고 내보기는 다음과 같이 내
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.Book>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Create</title>
</head>
<body>
<% using (Html.BeginForm(new { enctype = "multipart/form-data" }))
{%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.name) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.name) %>
<%: Html.ValidationMessageFor(model => model.name) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.author) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.author) %>
<%: Html.ValidationMessageFor(model => model.author) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.picture) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.picture) %>
<%: Html.ValidationMessageFor(model => model.picture) %>
</div>
<input type='file' name='picture1' id='picture1' />
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
나는 많은 것들을 시도했지만 내가 모든 파일을 업로드 할 수
. 내가 무엇을 할 수 있을지?
문제가 무엇을해야 하는가? 'picture1'은 널입니까? –