Ale*_*lex 3 .net asp.net-mvc jquery jeditable
我理解,使用jEditable(http://www.appelsiini.net/projects/jeditable),您可以进行就地编辑并将更改的信息POST到URL.
我的ASP.NET MVC视图显示了一堆模型信息,我想在其中进行就地编辑.目前,我有两个视图 - 一个文本表示和一个编辑视图,其中一个表单完全POST,然后我的控制器操作将整个对象(从表单元素名称组装)作为参数,更新对象并返回到文本 - 只能查看.
但是,当我切换到jEditable时,我只会使用文本视图并一次POST一个项目,而不是整个对象.我怎么能构建一个单独的控制器动作,可以采取jEditable的POST,然后将其放入我的对象的相应属性?
这里有一些非常好的示例代码:
$("#myTextBox").editable('<%=Url.Action("UpdateSettings","Admin") %>', {
submit: 'ok',
cancel: 'cancel',
cssclass: 'editable',
width: '99%',
placeholder: 'emtpy',
indicator: "<img src='../../Content/img/indicator.gif'/>"
});
[AcceptVerbs("POST")]
public ActionResult UpdateSettings(string id, string value)
{
// This highly-specific example is from the original coder's blog system,
// but you can substitute your own code here. I assume you can pick out
// which text field it is from the id.
foreach (var item in this.GetType().GetProperties())
{
if (item.Name.ToLower().Equals(id, StringComparison.InvariantCultureIgnoreCase))
item.SetValue(Config.Instance, value, null);
}
return Content(value);
}
Run Code Online (Sandbox Code Playgroud)
您可能还需要这个:http:
//noahblu.wordpress.com/2009/06/17/jeditable-note-dont-return-json-and-how-to-return-strings-from-asp-net-mvc-动作/
| 归档时间: |
|
| 查看次数: |
3976 次 |
| 最近记录: |