c# - POSTing self referencing model back to controller results in null object? -
is possible pass never ending self referencing model view controller? when submit form fiddler captures posting method settings[index].settings[index].value. actionresult save(settingsection settings) doesn't capture values being posted form. details below of code.
here self referencing model
public class settingsection : setting { public list<settingsection> children { get; set; } public list<settingsection> settings { get; set; } #region public methods public string getvalue(string path) { // find value json structure based on path return ""; }
here base class
public class setting { #region fields private string _name; private string _text = ""; private string _description = ""; private string _enumerationname = ""; private string _overridevalue = null; private datatype _settingtype; private string _value; private propertyinfo _propertyinfo; private type _enumtype; #endregion fields #region constructors public setting() { } public setting(string name, datatype settingtype, string svalue) { _name = name; _settingtype = settingtype; _value = svalue; } #endregion constructors #region public properties public string description { { return _description; } set { _description = value; } } public string enumerationname { { return _enumerationname; } set { _enumerationname = value; } } public string name { { return _name; } set { _name = value; } } public string text { { return _text; } set { _text = value; } } public string caption { { return string.isnullorwhitespace(_text) ? _name : _text; } } public string overridevalue { { if (_overridevalue == null) return _value; return _overridevalue; } set { _overridevalue = value; } } public datatype settingtype { { return _settingtype; } set { _settingtype = value; } } public string value { { return _value; } set { _value = value; } } #endregion public properties #region public methods #endregion public methods }
here view
@using (html.beginform("save", "settings", formmethod.post)) { @html.antiforgerytoken() { (var = 0; < model.settings.count; a++) { <div>@model.settings[a].text</div> (var e = 0; e < model.settings[a].settings.count; e++) { <div>@model.settings[a].settings[e].text</div> <div> @if (model.settings[a].settings[e].text == "true" || model.settings[a].settings[e].text == "false") { @html.checkboxfor(model => convert.toboolean(model.settings[a].settings[e].value)) } else { @html.textboxfor(model => model.settings[a].settings[e].value) } </div> <div> @for (var = 0; < model.settings[a].settings[e].children.count; i++) { <div style="margin-left: 50px"> @model.settings[a].settings[e].children[i].text @if (model.settings[a].settings[e].children[i].value == "true" || model.settings[a].settings[e].children[i].value == "false") { @html.checkboxfor(model => convert.toboolean(model.settings[a].settings[e].children[i].value)) } else { @html.textboxfor(model => model.settings[a].settings[e].children[i].value) } </div> } </div> } } <div class="row"> <div class="col-md-2"></div> <div class="col-md-1"> <button type="submit" class="form-control btn btn-success" value="save"> <i class="fa fa-save"></i> save </button> <!--html.actionlink("save", "save", "settings", null, new { settings = mod })--> </div> <div class="col-md-1"> <a href="" class="form-control btn btn-danger"><i class="fa fa-times"></i><label>cancel</label></a> </div> </div> }
here controller
public actionresult save(settingsection settings) { //settings == null, why? var b = settings; return view(settings); }
Comments
Post a Comment