特定のフィールドのデータを編集したいと思います。私が得ている問題は、たとえばフィールド名が文字列であるということです。私はそのフィールドを取得し、jeditableを使ってAjaxを介して、私のコントローラを呼び出す私のモデルの動的フィールド - ASP.NET MVC 3
<div class="editable" id="cnso">@Model.cnso</div>
:
$('.editable').editable('/Req/UpdateField', {
tooltip: 'Click to edit...',
submitdata : {
nreqid : function() {
return $("#nreqid").val();
}
}
});
私のコントローラは、フィールドの名前を得た(私の見解で
私はこのようなパラメータを持っていますcnso)を文字列id
に挿入します。問題は私のモデルを更新することです。私のコントローラのいくつかのコード。
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 !!!
}
}
マイモデルオブジェクト、Req
は、フィールドcnso
を持っている、と私id
文字列は「CNSO」を持っているので、どのように私は私の文字列IDからcnso
を選択することができますか?あなたができる反射使用
このReqオブジェクトはどのように見えますか?そのフィールドがあなたの文字列名と一致するreqのフィールドを更新したいのですか? – DMulligan
@AFinkelstein、重要な部分はObject Reqにフィールドcnsoがあることです。私の文字列IDには、割り当てたい文字列 "cnso"があります。 –