jQuery ajax .
1) . " ", "", m ( JQuery UI ), , ajax. , jquery
2) Inpage " ", , ( javascript ), , jQuery ajax post. json. ViewModel,
HTML
<a href="#" id="addNew"> Add Guest</a>
<div id="divForm" style="display:none">
<input type="text" id="txtName" />
<input type="text" id="txtEmail" />
<input type="button" id="btnSaveGuest" value="Save"/>
</div>
<ul>
<div id="divGuests"></div>
script
$(function(){
$("#addNew").click(function(){
$("#divForm").fadeIn(300);
});
$("#btnSaveGuest").click(function() {
var name=$("#txtName").val();
var email=$("#txtEmail").val();
$.ajax({
url: '@Url.Action("SaveGuest","Guest")',
data: {Name: name, EmailAddress :email},
success: function(data) {
if(data=="true")
{
$("#divGuests").append("<p>"+name+"</p>");
}
else
{
}
}
});
});
});
Action
[HttpPost]
public ActionResult SaveGuest(Guest objGuest)
{
try
{
return "true";
}
catch(Exception e)
{
return "false";
}
}
: http://jsfiddle.net/Qzk3F/16/
( )