Asp.net mvc 3 提交表单时DropdownList为空(MVC3)
我有一个创建页面和下拉列表。我的问题是,当我提交表单时,dropdownlist为空。请帮忙。这是我的密码 阶级 创建获取 看法 @型号MVCViewState.Models.ProductAsp.net mvc 3 提交表单时DropdownList为空(MVC3),asp.net-mvc-3,Asp.net Mvc 3,我有一个创建页面和下拉列表。我的问题是,当我提交表单时,dropdownlist为空。请帮忙。这是我的密码 阶级 创建获取 看法 @型号MVCViewState.Models.Product @{ ViewBag.Title = "Create"; } <h2>Create</h2> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Product</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Types)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.Types, Model.Types)
@Html.ValidationMessageFor(model => model.Types)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
创建帖子
我认为您的目的是获取所选类型的值。所以你需要这样的东西:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<SelectListItem> Types { get; set; }
public int TypeId { get; set; } // the selected type from the dropdown
}
我认为您的目的是获取所选类型的值。所以你需要这样的东西:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<SelectListItem> Types { get; set; }
public int TypeId { get; set; } // the selected type from the dropdown
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<SelectListItem> Types { get; set; }
public int TypeId { get; set; } // the selected type from the dropdown
}
@Html.DropDownListFor(model => model.TypeId, Model.Types)