部分ビューをレンダリングできるように、ajax を介してフォームをコントローラーに投稿しようとしています。
これが私のAjaxコードです
var formCollection = $('#some-form');
$(function(){ $('#some-form').submit(function(){
$.ajax({
type: "POST",
url: "/Trusk/Index",
data: formCollection,
dataType: "html",
success: function (result) {
$('#newView').html(result);
},
error: function (request, status, error) {
alert('Oh no!');
}
});
});
});
私のフォームのコード、ID = newView で部分ビューをレンダリングする必要があります。部分ビューはコントローラーによって返されます
<% using (Html.BeginForm(new { @id = "some-form" }))
{ %>
<div id="TestDiv">
<div id="Title">Test</div>
<div id="CheckIn">Check-in:<br />
<%:Html.TextBox("FromDate", "", new { @id = "DateFrom", @style = "width:190px" })%></div>
<div id="CheckOut">Check-out:<br />
<%:Html.TextBox("ToDate", "", new { @id = "DateTo", @style = "width:190px" })%><br /></div>
<div id="newView">
</div>
<input type="submit" value="Search" />
</div>
</div>
<% } %>
私のコントローラーコード
public ActionResult Index(FormCollection post)
{
ITruckRepository hotelRep = new TruckRepository();
IEnumerable<Truck> AvailableTrucks = hotelRep.getTrucks('2012,3,2', '2012,3,5');
return PartialView("Search", AvailableTrucks );
}
Ajax 経由でコントローラーに正しいパラメーターを渡しますか?
ありがとう