下载mvc4的EditForModel

时间:2013-07-24 10:15:51

标签: c# asp.net-mvc-4 razor

我们正在使用EditorForModel()

的动态视图
@model dynamic

@using (Html.BeginForm("Edit", null, FormMethod.Post, new { id="FrmIndex" }))
{
@Html.ValidationSummary(true);
@Html.EditorForModel()

 <input type="submit" value="Edit" />
}

我们的模型是:

    [UIHint("TextBox")]
    public string FirstName { get; set; }

    [Required]
    [UIHint("TextBox")]
    public string LastName { get; set; }

    [UIHint("DropDownList1")]
    public int deptId { get; set; }

    [UIHint("DropDownList2")]
    public int orgId { get; set; }

由于deptId和orgId是外键,我们需要从各自的表中填充所有可能的值,用户可以选择。

问题是有更多的DropDownList编辑器模板。

有什么方法可以最好地处理???

假设某个其他模型有5个外键,我们将有5个DropDownList编辑器模板看起来很奇怪。

DropDownList1.cshtml

@Html.DropDownList("",(IEnumerable<SelectListItem>)ViewBag.DropDownList1, "Choose..." ,  new { @class ="combo"})

DropDownList2.cshtml

@Html.DropDownList("",(IEnumerable<SelectListItem>)ViewBag.DropDownList2, "Choose..." ,  new { @class ="combo"})

请告知是否还有其他选项可以最好地实施。

0 个答案:

没有答案