我有一个表格,把照片上载到我的数据库,我利用一种观点模式协助这一进程。
观点模式:
public class GalleryViewModel
{
//Members:
public Gallery _photo { get; set; }
public string _title { get; set; }
public string _description { get; set; }
public string _photographer { get; set; }
public HttpPostedFileBase uploadFile { get; set; }
// Ctor
public GalleryViewModel(Gallery photo)
{
_photo = photo;
}
public GalleryViewModel()
{
_photo = null;
}
}
When I debug the code, I see that the in the post method in my controller, all the information from the form is updated in the view model except for the uploadFile which is null. In the form I use enctype = "multipart/form-data". When I use my master page the uploadFile is null but when I use the default MVC master page everything works fine.
页: 1
<%@ Master Language="C#" MasterPageFile="~/views/Shared/GeneralMaster.master" Inherits="System.Web.Mvc.ViewMasterPage" %>
<asp:Panel ID="notifiactions" runat="server">
<% if (ViewData["notifications"] != null)
{ %>
<br />
<table width="100%">
<tr>
<td align="center">
<div id="messages" style="width: 90%; border: solid 1px #A3A3A3">
<br />
<%= Html.Encode(ViewData["notifications"])%>
<br /><br />
</div>
</td>
</tr>
</table>
<% } %>
</asp:Panel>
<br />
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" align="center">
<img src="ContentSiteDesignwine_in_frame2.JPG" alt="lk" />
</td>
<td width="40%">
<asp:ContentPlaceHolder ID="PageContent" runat="server" />
</td>
<td width="30%" align="right">
<img src="ContentSiteDesignset_with_frame.jpg" alt="Alon" />
</td>
</tr>
</table>
这里是缺省总页。
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<div id="header">
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
</ul>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
任何想法?