Reputation: 58
My requirement is to load a partial view as a modal popup. On my popup there is a textbox and a verify button. I need to call a ajax request for verify button. And show the status accordingly. This is working fine for me but when i google it, most of the site show that updatetargetid as a parmeter in ajax.beginform. My question is that Is ajax.beginform updatetargetid is required ?
Here is my View.
@using (Ajax.BeginForm("VerifyDateOfBirth", new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "Loaded"
}))
{
<div>
<label for="dateOfBirth">
Date Of Birth
</label>
<br />
@Html.TextBox("dateOfBirth", null, new { @class = "dob", @readonly = "true" })
</div>
<button type="submit" id="btnVerify" value="VerifyDateOfBirth" class="">
Verify</button>
<span id="verifiedStatus" style="color: Blue; display: none;">* Data Match</span>
<span id="notverifiedStatus" style="color: Red; display: none;">* Data Not Match</span>
}
Here is my Javascript
function Loaded(data) {
var enteredDateOfBirth = $("#dateOfBirth").val();
if (data) {
var json = data.get_response().get_object();
if (json != null && json.DOB != "") {
if (enteredDateOfBirth == json.DOB) {
//alert('result ' + json.DOB);
$("#verifiedStatus").show();
}
else {
$("#notverifiedStatus").show();
}
}
}
}
Here is my controller
[HttpPost]
public ActionResult VerifyDateOfBirth(string dateOfBirth)
{
//TODO : Get data from db
var data = new PremiumCalculationASView
{
DOB = DateTime.Now.ToString("dd/MM/yyyy") //dateOfBirth
};
return Json(data);
}
This is working fine for me. Is updatedtargetid is required here
Upvotes: 0
Views: 2469
Reputation: 10694
UpdatetargetId
is optional parameter.
UpdatetargetId
is the id of the DOM element which you want to update depending upon repsonse from the server.
If you are returning any View
or PartialView
from controller
using Ajax.BeginForm
. This DOM element will be updated and will have view content you have returned.
In your case, as far as I know, you wont need to specify UpdateTargetID
Upvotes: 1