这是我的模型代码
public class ManufacturerModel
{
public int ProductTYpeId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public List<SelectListItem> manf { get; set; }
public Manufacturer manufacturer { get; set; }
}
这是我在cshtml文件中的代码
@using (Html.BeginForm("addmanufacturer", "Admin", FormMethod.Post, new { id = "formPageID" }))
{
<div class="row">
<label>Select Existing Manufacturer<span style="color: Red">*</span>:</label>
<div class="formRight">
@Html.DropDownList("Id", Model.manf)
</div>
</div>
<div class="row">
<label>Manufacturer Name<span style="color: Red">*</span>:</label>
<div class="formRight">
@Html.TextBoxFor(m => m.manufacturer.name)
@Html.ValidationMessageFor(m => m.manufacturer.name)
</div>
</div>
}
我正在发布此表格,当我试图从制造商那里获取价值时,即 - ManufacturerModel 制造商 = new ManufacturerModel(); 使用模型对象,所有值都为空。
在文本框中如果我用 m => m.Name 替换它,那么我可以获得正确的 Name 值。任何人都可以提出问题所在
我正在使用 manf 绑定下拉菜单。如果我发回表单并且如果它返回,则值变为空白,我需要重新填写该值..
public ActionResult addmanufacturer(string id)
{
if (id == null)
id = "0";
ManufacturerModel manufacturer = new ManufacturerModel();
manufacturer.ProductTYpeId = Convert.ToInt32(id);
manufacturer.manf = GetManf();
manufacturer.Id = -1;
return View(manufacturer);
}