2010-11-02 49 views
1

如果我碰巧有如何处理`PartialRender`模型?

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; } 
} 

任何手段,在我View我有一个正常的形式来填充模型属性,但List<DoorDesignModel>我使用的是用户控制和使用

<%Html.RenderPartial("DoorDesign", Model.Doors); %> 

里面DoorDesign.ascx我:

<%@ Control 
     Language="C#" AutoEventWireup="true" 
     Inherits="System.Web.Mvc.ViewUserControl<List<MyProject.Backend.Models.DoorDesignModel>>" %> 

显示所有形式我有一个for条款

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 %>]"> 

但很快我按下提交按钮,我的模型返回null列表:( ,我创建和设置一个新的列表开始查看

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部分归还门列表?

查看

alt text

+0

1.您已经创建了一个DoorsModel型号 活页夹? 2.您是否将From enctype设置为“multipart/form-data”? – Bivoauc 2010-11-02 23:19:56

+0

@Bivoauc 1.是的,你可以把它看作是在用户控件中继承我的模型-2。是的,我在用户控件之外使用'Image'工作并且效果很好。 – balexandre 2010-11-03 07:39:27

回答