0
A
回答
2
我想你要做到这一点,当你在编辑界面更新实体记录,以获得其他属性值的原因。您可能正在编辑一些属性(并且只有那些属于您的表单),并且您可能会获得null
以用于所有其他不属于表单的属性。
你应该做的是,只将PostID属性保留在表单的隐藏字段中,并在你的HttpPost
操作方法中,读取实体并仅更新从表单发送并保存的那些属性。
[HttpPost]
public ActionResult Edit(Post model)
{
var existingPost=repositary.GetPost(model.PostID);
//Set only the properties posted from form to the existingPost entity
existingPost.Title=model.Title;
var result= repositary.SavePost(existingPost);
return RedirectToAction("PostSaved",new {@id=model.PostID});
}
0
您可以使用http://jqueryui.com/dialog/来显示确认窗口。点击确定按钮指定表单提交。 请看下面的例子:
@using(Ajax.BeginForm("Edit", "Post", null, new AjaxOptions { HttpMethod = "POST" }, new {@id = "frmPost" , enctype = "multipart/form-data" }))
{
@Html.EditorForModel()
}
<div id="dialog">Some confirmation</div>
<script>
$("#dialog").dialog({
modal: true,
buttons: {
Ok: function() {
$("#frmPost").submit();
$("#dialog").dialog('close');
},
Cancel: function() {
$(this).close();
}
}
});
</script>
相关问题
- 1. 隐藏所有字段/字段集中的所有字段
- 2. Rails:如何隐藏模型的属性?
- 3. 隐藏Rails的模型属性
- 4. 隐藏属性的Java字段
- 5. Rails - 隐藏模型属性_Form
- 6. 在ActiveRecord模型中隐藏属性
- 7. Django隐藏模型中的假字段
- 8. django modelform属性隐藏字段
- 9. 数据注解隐藏属性/字段
- 10. 为Asp.net MVC 3模型的所有属性添加隐藏字段的最简单方法?
- 11. 将隐藏字段的int列表绑定到MVC中模型的属性c#?
- 12. 为什么隐藏的字段目标不需要是模型的属性?
- 13. 在django中隐藏模型字段
- 14. ASP.NET MVC3:模型隐藏字段结合
- 15. 模型活页夹和隐藏字段
- 16. 从django模型中隐藏字段
- 17. 将所有字段隐藏为表单
- 18. 隐藏字段持久性
- 19. 隐藏属性
- 20. 如何在loopbackjs中取消隐藏隐藏在基础模型中的属性?
- 21. 修改Laravel模型的所有属性
- 22. Ember.js - 过滤模型的所有属性
- 23. 模型中有很多字段,但想拥有所有这些字段的公有/私有属性
- 24. 隐藏代码隐藏的HTML属性
- 25. CSS隐藏所有具有匹配SRC属性的图像
- 26. 如何隐藏所有具有特定属性集的元素?
- 27. 访问模型字段属性在Django
- 28. django模型属性字段空列表
- 29. 自定义字段/属性模型
- 30. 更改旧文档的富文本字段的隐藏属性
你想这么做的原因是什么? – Shyju
[在C#中通过对象属性循环]的可能重复(http://stackoverflow.com/questions/957783/loop-through-an-objects-properties-in-c-sharp) – Curt
如果您希望这种情况自动发生,你将需要使用反射。 – Maess