Suppose I want to use the ajax action reference to keep a single field unchanged for presentation.
Here is my view (this is a strongly typed view associated with the Model type):
<%= Html.TextBox("myComment", Model.MyComment)%>
<%= Ajax.ActionLink("SAVE", "SaveComment", "Home",
Model, new AjaxOptions { HttpMethod = "POST"})
%>
Here is my action for ajax actionlink in the controller:
[AcceptVerbs(HttpVerbs.Post)]
public void SaveComment(Model model)
{
MyRepository repository = new MyRepository();
Model mod = repository.GetModel(model.ID);
mod.MyComment = model.MyComment;
try
{
repository.Save();
}
catch(Exception ex)
{
throw ex;
}
}
The problem is that I cannot get user input in the text box for Mycomment in the action method. No matter which user enters the browser for Mycomment, when I click on Ajax ActionLink SAVE, I check the value from the param model for Mycomment, nothing has changed for MyComment.
Confused is: The model must be tied to view in two directions. but for this case, it seems not. Then I changed the Ajax.ActionLink call to:
Ajax.ActionLink("SAVE", "SaveComment", "Home",
new {commentinput =Model.MyComment, new AjaxOptions { HttpMethod = "POST"})
:
public void SaveComment(string commentinput)
.
?