checkboxfor

MVC3 - Viewmodel with list of complex types

懵懂的女人 提交于 2019-11-28 05:27:27
Apologies if this has been asked before; there are a million ways to phrase it so searching for an answer has proved difficult. I have a viewmodel with the following properties: public class AssignSoftwareLicenseViewModel { public int LicenseId { get; set; } public ICollection<SelectableDeviceViewModel> Devices { get; set; } } A simplified version of SelectableDeviceViewModel would be this: public class SelectableDeviceViewModel { public int DeviceInstanceId { get; set; } public bool IsSelected { get; set; } public string Name { get; set; } } In my View, I am attempting to display a list of

ASP.net MVC CheckBoxFor casting error

拥有回忆 提交于 2019-11-27 07:35:42
问题 I have a EF entity that is tied to a SQL table that contains a bit field called "Active". I generate the Edit code from the T4 template, and the page inherits from the EF entity. At the bottom of the page, it generated a CheckBoxFor like this: <%= Html.CheckBoxFor(model => model.Active) %> I get the wonderful red squiggly under model.Active, and the error message says that I cannot implicitly convert type bool? to bool. So, I tried the following: <%= Html.CheckBoxFor(model => (bool)model

MVC3 - Viewmodel with list of complex types

不打扰是莪最后的温柔 提交于 2019-11-27 00:57:13
问题 Apologies if this has been asked before; there are a million ways to phrase it so searching for an answer has proved difficult. I have a viewmodel with the following properties: public class AssignSoftwareLicenseViewModel { public int LicenseId { get; set; } public ICollection<SelectableDeviceViewModel> Devices { get; set; } } A simplified version of SelectableDeviceViewModel would be this: public class SelectableDeviceViewModel { public int DeviceInstanceId { get; set; } public bool

Proper usage of .net MVC Html.CheckBoxFor

倖福魔咒の 提交于 2019-11-26 10:31:20
All I want to know is the proper syntax for the Html.CheckBoxFor HTML helper in ASP.NET MVC. What I'm trying to accomplish is for the check-box to be initially checked with an ID value so I can reference it in the Controller to see if it's still checked or not. Would below be the proper syntax? @foreach (var item in Model.Templates) { <td> @Html.CheckBoxFor(model => true, item.TemplateId) @Html.LabelFor(model => item.TemplateName) </td> } Robert Koritnik That isn't the proper syntax The first parameter is not checkbox value but rather view model binding for the checkbox hence: @Html