@using(Html.BeginForm("About", "User", FormMethod.Post , new { id="aboutme"}))
{
<fieldset>
<ul>
<li> <label class="block">About me</label> @Html.TextAreaFor(m=>m.About.AboutMe)</li>
<li> <input type="button" id="submit" class="input-button" /> </li>
</ul>
</fieldset>
}
<script type="text/javascript">
$(function() {
$('#submit').click(function() {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
// The AJAX call succeeded and the server returned a JSON
// with a property "s" => we can use this property
// and set the html of the target div
alert(result.s);
$('#ShowResultHere').html(result.s);
}
});
// it is important to return false in order to
// cancel the default submission of the form
// and perform the AJAX call
return false;
});
});
</script>
當我調試這個時,動作URL變成/User/undefined
。MVC 4 Ajax發佈不起作用
我該如何解決?
是的,我想通了。謝謝。 – DarthVader