如何处理`PartialRender`模型? [英] How to handle `PartialRender` Models?
问题描述
如果以任何方式我碰巧有
if by any means I happen to have
public class DoorsModel
{
public DoorsModel() { }
public HttpPostedFileBase Image { get; set; }
public String DoorLayout { get; set; }
public bool ReplicateSettings { get; set; }
public List<DoorDesignModel> Doors { get; set; }
}
public class DoorDesignModel
{
public DoorDesignModel() { }
public HttpPostedFileBase FrontFile { get; set; }
public HttpPostedFileBase BorderFile { get; set; }
}
在我的查看
我有一个正常的形式来填充模型属性,但列表&LT; DoorDesignModel&GT;
我M使用的用户控制和使用
and in my View
I have a normal form to populate the Model Properties but the List<DoorDesignModel>
I'm using a User Control and use
<%Html.RenderPartial("DoorDesign", Model.Doors); %>
在 DoorDesign.ascx
我有:
<%@ Control
Language="C#" AutoEventWireup="true"
Inherits="System.Web.Mvc.ViewUserControl<List<MyProject.Backend.Models.DoorDesignModel>>" %>
显示所有表格我有一个为
条款
MyProject.Backend.Models.DoorDesignModel field;
for (i = 0; i < Model.Count; i++) {
field = Model[i];
...
}
和我使用HTML
<input type="file" value="Upload file"
name="Doors.FrontFile[<%: i %>]" id="Doors.FrontFile[<%: i %>]">
但很快我preSS提交按钮,我的模型返回空
列表:(
而我创建和设置启动查看时,一个新的列表
but soon I press the submit button, my model returns a null
List :(
and I'm creating and setting a new list when starting the View as
public ActionResult Doors()
{
DoorsModel model = new DoorsModel();
model.Doors = new List<DoorDesignModel>();
for (int i= 1; i<= 24; i++) // Add 24 Doors
model.Doors.Add(new DoorDesignModel());
return View(model);
}
[HttpPost]
public ActionResult Doors(DoorsModel model)
{
// model.Doors is always null !!!
if (ModelState.IsValid)
ViewData["General-post"] = "Valid";
else
ViewData["General-post"] = "NOT Valid";
return View(model);
}
什么我需要有为了从的RenderPartial
部分返回门列表?
视图的简单样机
推荐答案
刚刚有同样的问题。发现这个网站:<一href=\"http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx\" rel=\"nofollow\">http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx
Just had the same problem. Found this website: http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx
从本质上讲它是所有关于&LT;输入类型=文件VALUE =上传文件NAME =门[&LT;%:I%]的计算值FrontFile。ID =门[&LT;%:I%&GT; ] .FrontFile&GT;
Essentially it is all about
<input type="file" value="Upload file" name="Doors[<%: i %>].FrontFile" id="Doors[<%: i %>].FrontFile">
这篇关于如何处理`PartialRender`模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!