I want to edit the data of a specific field. The problem I got is that the field name is a string, for example.
In my view I have the parameter like this:
<div class="editable" id="cnso">@Model.cnso</div>
I get that field and call my controller via Ajax using jeditable:
$('.editable').editable('/Req/UpdateField', {
tooltip: 'Click to edit...',
submitdata : {
nreqid : function() {
return $("#nreqid").val();
}
}
});
My controller got the name of the field (cnso) in the string id. The problem is to update my model. Some code of my controller.
public string UpdateField(string id, string value, int nreqid)
{
/*
* id - id of the field. This value can be used on the
* server side to determine what property of the
* company should be updated.
* value - text that is entered in the input field.
* nreqid - this is additional parameter that will
* be added to the request. Value of this parameter
* is a value of the hidden field with an id "ReqId".
*/
ModelState.Clear();
if (ModelState.IsValid)
{
//db.Entry(req).State = EntityState.Modified;
//db.SaveChanges();
Req req = db.Req.Find(nreqid);
req."id" = "2"; // <--- Problem here !!!
}
}
My model object, Req, has the field cnso, and my id string has the "cnso", so how can I select the cnso from my string id?