I would put the possible options in the drop-down list, and then use jquery to make a JSON request to get data from your controller, and then a save button that calls another javascript function to send the changed data back to the controller.
controller:
public ActionResult GetFields() { var model=new MyModel(); model.Selections =(from m in database.table select m.Field1).ToList(); return View(model); } public ActionResult GetComments(string field1) { return Content((from c in database.table where(c.Field1==field1)select c.Comments).First()); } [HttpPost] public void SaveComments(string field1, string comments) { var record=(from r in database.table where(r.Field1==field1)select r).First(); record.Comments=comments; database.SaveChanges; return; }
View:
<script type="text/javascript> function SaveComments(){ var url='@Url.Action("GetComments","YourControllerName"); url+='?field1='+$('#selections option:selected').text(); $('#selectedField').text($('#selections option:selected').text()); $('#commentEditor').load(url); }; function SaveComments(){ var url='@Url.Action("SaveComments","YourControllerName")'; url+='?field1='+$('#selections option:selected').text()+'&comments='+$('#commentEditor').text(); $('#dummy').load(url); }; </script> <select id="selections" onchange="SelectionChanged()"> @foreach(var item in Model.Selections) { <option value="@item">@item</option> } </select> <div id="selectedField"/> <input type="text" id="commentEditor"/> <input type="button" value="apply" onclick="SaveComments()"/> <div id="dummy"/>
Disclaimer: there may be small errors (usually do not write large chunks of code in the text box: P), you probably should not use a dummy div, and you will need to have a List in your view model whose return returns to based on values ββin Selections. This should give you a general idea.
Joshua smith
source share