【发布时间】:2013-01-04 19:00:46
【问题描述】:
我正在使用 asp.net mvc 4 有没有办法根据用户的选择更新表单?
(在这种情况下,如果从下拉列表中选择了某些内容,我想填写地址字段,否则需要输入新地址)
我的模型: 公共类 NewCompanyModel {
[Required]
public string CompanyName { get; set; }
public bool IsSameDayRequired { get; set; }
public int AddressID { get; set; }
public Address RegisterOfficeAddress { get; set; }
}
查看:
@model ViewModels.NewCompanyModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "frm", id = "frm" }))
{
@Html.ValidationSummary(true)
<fieldset id="test">
<legend>Company</legend>
<h2>Register office address</h2>
<div class="editor-label">
@Html.LabelFor(model => model.AddressID)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.AddressID, (IList<SelectListItem>)ViewBag.Addresses, new {id = "address", onchange = "window.location.href='/wizard/Address?value=' + this.value;" })
</div>
<div class="editor-label">
@Html.LabelFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
@Html.ValidationMessageFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.RegisterOfficeAddress.StreetName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.RegisterOfficeAddress.StreetName)
@Html.ValidationMessageFor(model => model.RegisterOfficeAddress.StreetName)
</div>
和控制器:
public ActionResult Address(string value)
{
//get the address from db and somehow update the view
}
问题是如何更新“model.RegisterOfficeAddress.StreetName”等 只是为了说明这只是表单的一部分,所以我还不能提交。
非常感谢
【问题讨论】:
标签: c# asp.net-mvc