0
我有一个窗体,并在该窗体中的下拉列表项的值是字符串类型。我需要将所选列表项的值存储到Book.PublisherId,它是int。如何编辑下面的代码,假设PublisherId是字符串?发送到模型之前转换下拉列表值为int
@Html.DropDownListFor(model => model.Book.PublisherId, Model.items);
我有一个窗体,并在该窗体中的下拉列表项的值是字符串类型。我需要将所选列表项的值存储到Book.PublisherId,它是int。如何编辑下面的代码,假设PublisherId是字符串?发送到模型之前转换下拉列表值为int
@Html.DropDownListFor(model => model.Book.PublisherId, Model.items);
你不需要改变任何东西。如果Model.items中的值可以转换为int,则在提交表单后,您将在Book.PublisherId属性中获得正确的int值。
[将Dropdownlist项的值转换为int]可能的重复(http://stackoverflow.com/questions/11231997/convert-dropdownlist-items-value-to-int) – nemesv