私は先に進み、私が知っている唯一の方法でした。恐らく最良の方法ではありませんでしたが、うまくいきました。誰かがこれを達成するためのより良い方法を持っている場合私に知らせてください。
ユーザーが[テーブルの追加]ボタンを選択した後:私がやったこと
。
[制御装置1A]
public ActionResult AddTableTo(Int64 id)
{
var tableService = id;
var tableServiceName = db.VipServices.Single(x => x.VipServiceId == id);
var venueId = tableServiceName.Event.Venue.VenueId;
ViewData["TablerServiceNameFor"] = tableServiceName.Customer.FullName;
ViewData["TableServiceFor"] = tableService;
ViewBag.SeatingAreaId = new SelectList(db.SeatingAreas.Where(y => y.VenueId == venueId), "SeatingAreaId", "AreaName");
return View();
}
[ビュー#1]
@model ShadowVenue.ViewModels.VipSeatingAreaViewModel
@{
ViewBag.Title = "Select Seating Area";
}
<h2>Select Seating Area For:</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
<fieldset>
<legend>@ViewData.Eval("TablerServiceNameFor")'s Table(s)</legend>
<div class="editor-label">
Select Seating Area
</div>
<div class="editor-field">
@Html.DropDownList("SeatingAreaId", String.Empty)
</div>
@Html.Hidden("VipServiceId", ViewData.Eval("TableServiceFor"))
<p>
<input type="submit" name="nextButton" value="Next" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to Table Service Details", "Details", new { Id = ViewData.Eval("TableServiceFor") })
</div>
[コントローラ1bのコントローラ1Bは、処置AddTableToTable [コントローラ2]にリダイレクトし、送信
[HttpPost]
[Authorize(Roles = "Administrator, SuperUser")]
public ActionResult AddTableTo(VipSeatingAreaViewModel seatingArea, string nextButton)
{
if (nextButton != null)
return RedirectToAction("AddTableToTable", new { sid = seatingArea.SeatingAreaId, vid = seatingArea.VipServiceId });
return View(seatingArea);
}
選択されたSeatingAreaIdとVipServiceIdに沿って
[コントローラ2]
public ActionResult AddTableToTable(Int16 sid, Int64 vid)
{
var tableService = vid;
var tableServiceName = db.VipServices.Single(x => x.VipServiceId == vid);
var seatingAreaId = sid;
var seatingArea = db.SeatingAreas.Single(x => x.SeatingAreaId == sid);
ViewData["TablerServiceNameFor"] = tableServiceName.Customer.FullName;
ViewData["TableServiceFor"] = tableService;
ViewData["SeatingAreaName"] = seatingArea.AreaName;
ViewBag.TableId = new SelectList(db.Tables.Where(y => y.SeatingAreaId == seatingAreaId), "TableId", "TableName");
return View();
}
を見る#2 [ビュー#2]
@model ShadowVenue.ViewModels.VipTableViewModel
@{
ViewBag.Title = "Select Table";
}
<h2>Select Table For:</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
<fieldset>
<legend>@ViewData.Eval("TablerServiceNameFor")'s VIP Service</legend>
<div class="editor-label">
Select Table in the <b>@ViewData.Eval("SeatingAreaName")</b> Seating Area
</div>
<div class="editor-field">
@Html.DropDownList("TableId", String.Empty)
</div>
@Html.Hidden("VipServiceId", ViewData.Eval("TableServiceFor"))
<p>
<input type="submit" name="backButton" value="Back" />
<input type="submit" name="nextButton" value="Next" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to Table Service Details", "Details", new { Id = ViewData.Eval("TableServiceFor") })
</div>
をレンダリングし、私は、ユーザーにさまざまなシーティングエリアを選択するために戻ってまたは選択するためのオプションを与えますVIPサービスに追加するテーブル。ビューポストを[コントローラ2b]に選択すると、VipServiceとテーブルの多対多関係が追加されます。
[コントローラ部2b]
[HttpPost]
[Authorize(Roles = "Administrator, SuperUser")]
public ActionResult AddTableToTable(VipTableViewModel model, string backButton)
{
if (backButton != null)
{
return RedirectToAction("AddTableTo", new { id = model.VipServiceId });
}
if (ModelState.IsValid)
{
VipService v = db.VipServices.Single(x => x.VipServiceId == model.VipServiceId);
Table t = db.Tables.Single(x => x.TableId == model.TableId);
v.Tables.Add(t);
db.SaveChanges();
return RedirectToAction("Details", new { id = model.VipServiceId });
}
else
{
return View(model);
}
}
は最終的に私は、ユーザーがちょうど彼らが割り当てたいエリアやテーブルに触れて(クリック)することができますので、会場のビジュアルにドロップダウンリストを作るつもりです。
もう一度、誰かがより良い解決策を持っている場合は、私に知らせてください。
ありがとうございます。
私は既にViewModelのセットアップを行っていますが、私はその記事が私が求めていることとは何か関係がないことを知りません。 –