小さな問題があります。
私の行動は:
public ViewResult SearchForRooms(int HotelDDL)
{
List<Room> roomsInHotel = bl.ReturnRoomsPerHotel(HotelDDL);
return View(roomsInHotel);
}
アクションを呼び出しているjqueryは次のとおりです。
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#HotelDDL").change(function () {
var text = $("#HotelDDL option:selected").text();
var value = $("#HotelDDL option:selected").val();
alert("Selected text=" + text + " Selected value= " + value);
$.post("/Home/SearchForRooms",
{
HotelDDL: $("#HotelDDL option:selected").val()
});
});
});
</script>
そして最後に、これが呼び出されるべきビューです:
@model IEnumerable<RoomReservation.Entities.Entities.Room>
@{
ViewBag.Title = "Search";
}
<h2>Result</h2>
<table>
<tr>
<th>
City
</th>
<th>
Hotel
</th>
<th>
Room label
</th>
<th>
Number of beds
</th>
<th>
Price per night
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelitem=>item.Hotel.City.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Hotel.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.NumberOfBeds)
</td>
<td>
@Html.DisplayFor(modelItem => item.PricePerNight)
</td>
</tr>
}
</table>
最終的なビューのレンダリングを除いて、すべてが正常に機能しています(databseはすべての部屋を正しく返します)。Philのツールを試しましたが、疑わしいヒントは得られません。
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
では、jscriptがpostメソッドを送信した後に表示されないのはなぜSearchForRooms()
ですか?ありがとうございました
PS他のコードが必要な場合は、そのように言ってください。