Note that there are some explanatory texts on larger screens.

plurals
  1. POEnter 3 dates and display order in different VIEW, after click
    primarykey
    data
    text
    <p>Hey guys so im attempting to throw a project together to increase my knowledge of MVC3 but I have hit a wall...</p> <p>So from my HolidaysController inside my index 'view' I have created a hyperlink which will navigate the user to the 'create3' ActionResult</p> @Html.ActionLink("Select 3 Dates", "Create3") <hr> <p>In my create3 page I want the user to enter 3 dates into text boxes and when they click &#39;create&#39; the user will be returned to the previous HolidaysController/Index page where the dates will be displayed in order of ascending date</p> <p>....ATM I have this working up until the user enters 3 dates and clicks &#39;create&#39;...However I only know how to display a message box displaying the order, it is working I just need help getting the order to be displayed from the index page.</p> <p>Please see my code:</p> <h2> Code for HolidayController/Index:</h2> <pre><code> //submit will go to post [HttpPost] public ViewResult Index(int HolidayDate) { var holidays = db.Holidays.Include("Person"); HolidayList model = new HolidayList(); model.currentPersonID = HolidayDate; model.PList4DD = db.People.ToList(); model.Categories = holidays.Select(x =&gt; new SelectListItem { Value = x.Id.ToString(), Text = x.Person.Name } ); int data = HolidayDate; model.HList4DD = db.Holidays.Where(h =&gt; h.PersonId == HolidayDate).ToList(); return View(model); } [HttpGet] public ViewResult Index(string sortOrder, int? currentPersonID) { var holidays = db.Holidays.Include("Person"); HolidayList model = new HolidayList(); //not null if (currentPersonID.HasValue) { model.currentPersonID = currentPersonID.Value; } else { model.currentPersonID = 0; } model.PList4DD = db.People.ToList(); ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : ""; var dates = from d in db.Holidays where d.PersonId == currentPersonID.Value select d; switch (sortOrder) { case "date": dates = dates.OrderBy(p =&gt; p.HolidayDate); break; } model.HList4DD = dates.ToList(); return View(model); } </code></pre> <hr> <pre><code>//View for Index @*@model IEnumerable&lt;HolidayBookingApp.Models.Holiday&gt;*@ @model HolidayBookingApp.Models.HolidayList @{ ViewBag.Title = "Index"; } &lt;h2&gt;Index&lt;/h2&gt; &lt;p&gt; @Html.ActionLink("Create New", "Create") &lt;/p&gt; &lt;p&gt; @Html.ActionLink("Select 3 Dates", "Create3") &lt;/p&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt; PersonId &lt;/th&gt; &lt;th&gt; @*HolidayDate*@ @Html.ActionLink("HolidayDate", "Index", new { sortOrder = ViewBag.NameSortParm, currentPersonID = Model.currentPersonID }) &lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;/tr&gt; @foreach (var item in Model.HList4DD) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.PersonId) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.HolidayDate) &lt;/td&gt; &lt;td&gt; @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | @Html.ActionLink("Details", "Details", new { id = item.Id }) | @Html.ActionLink("Delete", "Delete", new { id = item.Id }) &lt;/td&gt; &lt;/tr&gt;} &lt;tr&gt; &lt;div class="editor-label"&gt; @* @Html.LabelFor(model =&gt; model.PList4DD, "Person")*@ &lt;/div&gt; &lt;div class="editor-field"&gt; &amp;lt;form action ="/Holidays/Index" id="some" method="post"&gt; @Html.DropDownListFor(model =&gt; model.HList4DD.First().HolidayDate, new SelectList(Model.PList4DD, "Id", "Name", Model.currentPersonID), "--select--") &amp;lt;script&gt; function updateFormEnabled() { if (verifyAdSettings()) { $('#sbmt').removeAttr('disabled'); } else { $('#sbmt').attr('disabled', 'disabled'); } } function verifyAdSettings() { if ($('#HolidayDate').val() != '') { return true; } else { return false; } } $('#HolidayDate').change(updateFormEnabled); &amp;lt;/script&gt; &amp;lt;input type="submit" id= "sbmt" name="ViewHolidaysDD" value="View"/&gt; &amp;lt;/form&gt; &amp;lt;script&gt; $('#sbmt').attr('disabled', ''); &amp;lt;/script&gt; &lt;/div&gt; &lt;/table&gt; &lt;br /&gt; &lt;br /&gt; &lt;table&gt; &lt;div&gt; Judging by your selection the order of dates are: //HERE IS WHERE I WANT TO DISPLAY THE ORDER OF DATES &lt;/div&gt; &lt;/table&gt; </code></pre> <h2>Just above is where I want to display my dates in order, ascending</h2> <pre><code>//my create 3 Action result [HttpGet] public ActionResult Create3() { return View(); } [HttpPost] public ActionResult Create3(string date1, string date2, string date3) { string FirstDateOrder, SecondDateOrder, ThirdDateOrder; //date 1 is biggest if (date1.Length &gt; date2.Length &amp;&amp; date1.Length &gt; date3.Length) { //date 2 is 2nd &amp; date 3 is 3rd if (date2.Length &gt; date3.Length) { FirstDateOrder = date1; SecondDateOrder = date2; ThirdDateOrder = date3; System.Windows.Forms.MessageBox.Show("Order is 1, 2, 3"); return RedirectToAction("Index"); } //date 3 is 2nd &amp; date 2 is 3rd else { FirstDateOrder = date1; SecondDateOrder = date3; ThirdDateOrder = date2; System.Windows.Forms.MessageBox.Show("Order is 1, 3, 2"); return RedirectToAction("Index"); } } //date 2 is biggest if (date2.Length &gt; date1.Length &amp;&amp; date2.Length &gt; date3.Length) { //date 1 is 2nd &amp; date 3 is 3rd if (date1.Length &gt; date3.Length) { FirstDateOrder = date2; SecondDateOrder = date1; ThirdDateOrder = date3; System.Windows.Forms.MessageBox.Show("Order is 2, 1, 3"); return RedirectToAction("Index"); } //date 3 is 2nd &amp; date 1 is 3rd else { FirstDateOrder = date2; SecondDateOrder = date3; ThirdDateOrder = date1; System.Windows.Forms.MessageBox.Show("Order is 2, 3, 1"); return RedirectToAction("Index"); } } //date 3 is biggest if (date3.Length &gt; date1.Length &amp;&amp; date3.Length &gt; date2.Length) { //date 1 is 2nd &amp; date 2 is 3rd if (date1.Length &gt; date2.Length) { FirstDateOrder = date3; SecondDateOrder = date1; ThirdDateOrder = date2; System.Windows.Forms.MessageBox.Show("Order is 3, 1, 2"); return RedirectToAction("Index"); } //date 2 is 2nd &amp; date 1 is 3rd else { FirstDateOrder = date3; SecondDateOrder = date2; ThirdDateOrder = date1; System.Windows.Forms.MessageBox.Show("Order is 3, 2, 1"); return RedirectToAction("Index"); } } return RedirectToAction("Index"); </code></pre> <h2> }</h2> <pre><code>and my view: @model HolidayBookingApp.Models.Dates @{ ViewBag.Title = "Create3"; } &lt;h2&gt;Create3&lt;/h2&gt; &amp;lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&amp;lt;/script&gt; &amp;lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&amp;lt;/script&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Dates&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.date1) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.date1) @Html.ValidationMessageFor(model =&gt; model.date1) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.date2) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.date2) @Html.ValidationMessageFor(model =&gt; model.date2) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.date3) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.date3) @Html.ValidationMessageFor(model =&gt; model.date3) &lt;/div&gt; &lt;p&gt; &amp;lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } &lt;div&gt; @Html.ActionLink("Back to List", "Index") &lt;/div&gt;"Index") &lt;/div&gt; </code></pre> <hr> <p>Not sure where to go from here something like create a paramter in the Index View which pulls across the order?</p> <p>Any help would be great thanks guys and sorry about the essay</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload