Hello,
In my page, I have a form that is bound to a Model. Their is a DropDownFor for a property named "TableName". Onchange event of this dropdown, I call a javascript method which calls one of the Action from the Controller and adds checkboxes for a property "RestrictEditFields" of type List. Here's the View Code :
- using (Html.BeginForm("TablePermissions", "Admin", FormMethod.Post, new { id = "tblPermForm" }))
- {
- @Html.AntiForgeryToken()
- class="form-horizontal">
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.TablePermission.TableName, htmlAttributes: new { @class = "control-label col-md-2" })
class="editor-field">- @Html.DropDownListFor(model => model.TablePermission.TableName,
- DbUtilities.GetTableNames(), "Select Table",
- new { @class = "form-control", @onchange="FillFields()" })
- @Html.ValidationMessageFor(model => model.TablePermission.TableName, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.RestrictEditFields, htmlAttributes: new { @class = "control-label col-md-2" })
class="editor-field">"editTable">
- }
FieldList class :
- public class FieldList
- {
- public string FieldName { get; set; }
- public bool Selected { get; set; }
- }
The data received thru json, has a list of fields and I display all those fields as check box. What I want to achieve is - basically, all selected Fields of checkboxes should be saved in Model.RestrictEditFields. And when the user selects that particular table again, all the fields should be displayed and if the value of Selected is true of a FieldList, then that check box should be marked selected.
I am a newbie in MVC and web, I don not get how do I implement this part. What would be the best approach for this ? After researching alot, I could finally add checkboxes dynamically. I am not able to figure out, how and where to bind it with the save & save to the model on clicking Save button. If anyone would help in providing guideline on how to proceed to achieve the goal, would be great.
Any help is highly appreciated.
Thanks a lot,

Terry146 reputationPosted Jul 31, 2017, 8:05 AM EDT
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jul 31, 2017, 5:08 AM EDT