我有一个具有 viewModel 的产品:ProductViewModel
private int _id;
private string _name;
private string _type;
private int _selectedID;
public ProductViewModel(int id, string name, string type)
{
_ id = id;
_ name = name;
_ type = type;
}
public int ProductID
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Type
{
get { return _type; }
set { _type = value; }
}
public int Selected
{
get { return _selected; }
set { _selected = value; }
}
为了显示产品列表,我还有另一个 ViewModel:ProductListViewModel
private PagedResult<ProductViewModel> _pagedResult;
private string _sortColumn = "Id";
private string _sortOrder = "ASC";
public LostAssetsListViewModel(PagedResult< ProductViewModel > products)
{
_pagedResult = products;
}
public PagedResult<ProductViewModel> List
{
get { return _pagedResult; }
set { _pagedResult = value; }
}
public string SortColumn
{
get { return _sortColumn; }
set { _sortColumn = value; }
}
public string SortOrder
{
get { return _sortOrder; }
set { _sortOrder = value; }
}
在我的视图中,我使用 Product LisViewModel 来显示产品列表。在我想添加单选按钮的每个产品中(选择该产品)
<% = Html.RadioButtonFor(m => m.List[i].Selected, "false", Model.List[i]. ProductID)%>
为了在我的控制器中获取所有数据,我创建了 ProductInputModel:
产品输入模型
private int _id;
private string _name;
private string _type;
private int _selectedID;
public ProductInputModel(int id, string name, string type)
{
_ id = id;
_ name = name;
_ type = type;
}
public int ProductID
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Type
{
get { return _type; }
set { _type = value; }
}
public int Selected
{
get { return _selected; }
set { _selected = value; }
}
在我的控制器中输入为空:[HttpPost] public ActionResult Details(ProductInputModel input) {}
我无法弄清楚为什么 ProductViewModel 中的数据没有传递给 ProductInputModel。我应该如何通过 ViewModels 获得选定的产品?