开发者

mvc 3 update model

开发者 https://www.devze.com 2023-02-13 00:40 出处:网络
I have a view that displays several checkbox lists of items in tables (the lists are dynamic).I need to know how to update the ViewModel when the user clicks on a checkbox so that when control returns

I have a view that displays several checkbox lists of items in tables (the lists are dynamic). I need to know how to update the ViewModel when the user clicks on a checkbox so that when control returns to the controller it can inspect the viewmodel to determine which items were sele开发者_开发问答cted.

The VM contains several properties such as

public IEnumerable<IFilterItem> Cities;

public Interface IFilterItem
{
   int ID { get; set; }
   string Name { get; set; }
   bool IsSelected { get; set; }
}

What I need help with is how to set the view's copy of the model data in the checkbox's onclick handler. Thanks as always, you guys are great!


Are you using the CheckBoxFor helper? If so, when control returns to the controller your view model should just have IsSelected set based on the state of the checkbox.

0

精彩评论

暂无评论...
验证码 换一张
取 消