【发布时间】:2014-05-05 09:10:10
【问题描述】:
我在访问控制器中的视图模型及其部分视图模型数据时遇到问题
我的模型
public class SearchRequest : BaseRequest
{
public SearchOptions SearchBy{ get; set; }
// and other properties also there
}
[KnownType(typeof(SearchByAirport))]
[KnownType(typeof(SearchByCity))]
[KnownType(typeof(SearchByProductCodes))]
[KnownType(typeof(SearchByGeocode))]
public abstract class SearchOptions
{
}
public class SearchByProductCodes : SearchOptions
{
public List<string> Codes { get; set; }
}
public class SearchByGeocode : SearchOptions
{
// few more properties
}
我的观点
View 具有SearchRequest 的模型参考,并有一个用于选择搜索类别的下拉菜单(即按产品代码、地理代码、城市等搜索),并且在更改下拉菜单时我会加载我的部分视图
我的一个部分观点
@model Tavisca.Catapult.External.DataContract.Common.SearchByProductCodes
<div class="form-group">
@Html.LabelFor(model => model.Codes, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Codes)
</div>
</div>
控制器
[HttpPost]
public ActionResult Create(SearchRequest hotelSearchRequest)
{
return View();
}
我在这里得到SearchBy Null,安排我的视图并将所有字段从视图获取到控制器的最佳方法是什么。
【问题讨论】:
标签: asp.net-mvc view asp.net-mvc-5 .net-4.5