What is the best way to create hidden fields for all model public properties?
I look for something like:
@Html.HiddenFor(t => t)
What is the best way to create hidden fields for all model public properties?
I look for something like:
@Html.HiddenFor(t => t)
I guess the reason you want to do this is to get the other property values when you update your entity record in an Edit screen. you may be editing a few properties (and only those are in your form) and you may be getting null
for all other properties which was not in the form.
What you should be doing is,Keep only the PostID property in a hidden field in your form and In your HttpPost
action method, Read the entity and update only those properties which was sent from the form and save it.
[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});
}
You could use http://jqueryui.com/dialog/ for displaying confirmation window. Specify form submit on Ok button click. See example below:
@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>