- セッションの値と現在のユーザーIDを比較するにはどうすればよいですか。
- ログインしているユーザーのレコードのみを表示する。
- ここでは、このビューを作成するために3つのテーブルを結合します。
if (Session["UserId"] == Model.userAccount.UserId)
ここで私はエラーが発生したコードです。
コード:
@model IEnumerable<OnlineTaxiReservationSystem.Models.BookingViewModel>
@{
ViewBag.Title = "Index";
}
<h2 id="h1">Bookings Detail</h2>
<p>
@Html.ActionLink("Add New Booking", "Create")
</p>
@if (Session["User"] == null)
{
Response.Redirect(Url.Action("Login", "Account"));
}
else if (Session["LoginRole"].ToString() == "Admin")
{
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.taxi.TaxiName)
</th>
<th>
@Html.DisplayNameFor(model => model.userAccount.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.BookingStartDateandTime)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.BookingEndDateandTime)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserContactNo)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserStartingLoaction)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserDistination)
</th>
<th>
@Html.DisplayNameFor(model => model.bookingStatus.Status)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.taxi.TaxiName)
</td>
<td>
@Html.DisplayFor(modelItem => item.userAccount.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.BookingStartDateandTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.BookingEndDateandTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserContactNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserStartingLoaction)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserDistination)
</td>
<td>
@Html.DisplayFor(modelItem => item.bookingStatus.Status)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.booking.BookingId }) |
@Html.ActionLink("Details", "Details", new { id = item.booking.BookingId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.booking.BookingId })
</td>
</tr>
}
</table>
}
else if (Session["UserId"] == Model.userAccount.UserId)
{
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.taxi.TaxiName)
</th>
<th>
@Html.DisplayNameFor(model => model.userAccount.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.BookingStartDateandTime)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.BookingEndDateandTime)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserContactNo)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserStartingLoaction)
</th>
<th>
@Html.DisplayNameFor(model => model.booking.UserDistination)
</th>
<th>
@Html.DisplayNameFor(model => model.bookingStatus.Status)
</th>
<th></th>
</tr>
@foreach (var item in @Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.taxi.TaxiName)
</td>
<td>
@Html.DisplayFor(modelItem => item.userAccount.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.BookingStartDateandTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.BookingEndDateandTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserContactNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserStartingLoaction)
</td>
<td>
@Html.DisplayFor(modelItem => item.booking.UserDistination)
</td>
<td>
@Html.DisplayFor(modelItem => item.bookingStatus.Status)
</td>
</tr>
}
</table>
}
エラーメッセージをお読みください。 – SLaks
'Model.userAccount'とはどういう意味ですか? – SLaks
どのようなエラーが表示されますか?ここで質問しているほとんどのユーザーには何らかのエラーがありますが、実際の例外メッセージを投稿することは、何が間違っているかを把握するのに役立ちます。 – Marco