I have a page in MVC3 with a link (Ajax.ActionLink). When the user clicks on it, it invokes the controller action, and the result is inserted into the div with replacement.
The code is shown below:
@Ajax.ImageActionLink("/Images/btn_share.png", "Share pool", "SharePool", new { poolKey = Model.Id, poolName = Model.Name },
new AjaxOptions {
UpdateTargetId="popup",
HttpMethod="GET",
InsertionMode = InsertionMode.Replace,
LoadingElementId="loading_dialog",
OnSuccess = "ShowPopup('#popup_share', true, true)"
}
ImageLinkAction is a custom extension method for using an image as a link, and ShowPopup is a javascript function that shows the updated div (so that it looks like a popup)
Now the markup code inserted into the div that creates the popup contains the form below
<div>
@using (Html.BeginForm()) {
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.EmailAddress)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EmailAddress)
@Html.ValidationMessageFor(model => model.EmailAddress)
</div>
// ... other fields
@Html.ValidationSummary(true)
<p>
<button type ="submit">Share</button>
</p>
}
</div>
submit: Submit , , . ajax, , ,
"" Ajax.ActionLink,
@Ajax.ActionLink("Share", "Share",
new Models.MyModel
{
ID = Model.ID,
EmailAddress = Model.EmailAddress
},
new AjaxOptions
{
UpdateTargetId="popup",
HttpMethod="POST",
InsertionMode = InsertionMode.Replace,
LoadingElementId="loading_dialog",
OnSuccess = "ShowPopup('#popup_share', true, true)"
}
:
[HttpPost]
public ActionResult SharePool(MyModel model)
{
return PartialView("_MyPartialView", model)
}
, Ajax ActionLink ( ) Model.EmailAddress , POST ID.
? , ,
OnBegin = "PreparePostData()"
javascript, , . , PreparePostData() routeValues ββ, ajax.
- , ?
, ?