Note that there are some explanatory texts on larger screens.

plurals
  1. PONothing being returned to POST event after edit of record
    primarykey
    data
    text
    <p>I am trying to edit a record. The Controller code is:</p> <pre><code> public ActionResult EditFixture(int id) { RLSBCWebSiteDb _context = new RLSBCWebSiteDb(); Fixture fixture = _context.Fixtures.Find( id ); ViewData["Gender"] = new SelectList( Fixture.GetGenderList(""), "Value", "Text", fixture.Gender ); ViewData["MatchTypeList"] = new SelectList( Fixture.GetMatchTypeList( "" ), "Value", "Text", fixture.MatchType ); ViewData["TeamNameList"] = new SelectList( Fixture.GetTeamNameList( "" ), "Value", "Text", fixture.TeamName ); ViewData["CommentsList"] = new SelectList( Fixture.GetCommentsList( "" ), "Value", "Text", fixture.Comments ); return View( fixture ); } [HttpPost] public ActionResult EditFixture( Fixture fixture ) { ViewData["Gender"] = new SelectList( Fixture.GetGenderList( "" ), "Value", "Text", fixture.Gender ); ViewData["MatchTypeList"] = new SelectList( Fixture.GetMatchTypeList( "" ), "Value", "Text", fixture.MatchType ); ViewData["TeamNameList"] = new SelectList( Fixture.GetTeamNameList( "" ), "Value", "Text", fixture.TeamName ); ViewData["CommentsList"] = new SelectList( Fixture.GetCommentsList( "" ), "Value", "Text", fixture.Comments ); if (ModelState.IsValid) { rlsbcWebSite.Fixtures.Add( fixture ); rlsbcWebSite.SaveChanges(); return RedirectToAction( "DisplayFixtures", new { id = fixture.MatchDate.Year.ToString() } ); } return View( fixture ); } </code></pre> <p>The view code is as follows:</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;RLSBCWebSite.Domain.Entities.Fixture&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; UpdateFixture &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h1&gt;Update the Fixture&lt;/h1&gt; &lt;% using (Html.BeginForm()) { %&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;Fixture&lt;/legend&gt; &lt;%: Html.HiddenFor(model =&gt; model.FixtureID) %&gt; &lt;%: Html.Partial("CreateOrEditFixture") %&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div class="grid_2"&gt; &lt;%: Html.ActionLink("Back to List", "Index") %&gt; &lt;br /&gt;&lt;br /&gt; &lt;/div&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content3" ContentPlaceHolderID="scriptContent" runat="server"&gt; &lt;/asp:Content&gt; </code></pre> <p>The code for the partial is as follows:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;RLSBCWebSite.Domain.Entities.Fixture&gt;" %&gt; &lt;%: Html.LabelFor(model =&gt; model.Gender) %&gt; &lt;%: Html.DropDownListFor( model =&gt; model.Gender, (ViewData["GenderList"] as SelectList) ) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Gender) %&gt; &lt;%: Html.LabelFor(model =&gt; model.MatchType) %&gt; &lt;%: Html.DropDownListFor( model =&gt; model.MatchType, (ViewData["MatchTypeList"] as SelectList) )%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.MatchType) %&gt; &lt;%: Html.LabelFor(model =&gt; model.TeamName) %&gt; &lt;%: Html.DropDownListFor( model =&gt; model.TeamName, (ViewData["TeamNameList"] as SelectList) )%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.TeamName) %&gt; &lt;%: Html.LabelFor(model =&gt; model.MatchDate) %&gt; &lt;%: Html.TextBox( "MatchDate", Model.MatchDate.ToShortDateString() )%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.MatchDate) %&gt; &lt;%: Html.LabelFor(model =&gt; model.Opponents) %&gt; &lt;%: Html.EditorFor(model =&gt; model.Opponents) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Opponents) %&gt; &lt;%: Html.LabelFor(model =&gt; model.Venue) %&gt; &lt;%: Html.EditorFor(model =&gt; model.Venue) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Venue) %&gt; &lt;%: Html.LabelFor(model =&gt; model.StartTime) %&gt; &lt;%: Html.EditorFor(model =&gt; model.StartTime) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.StartTime) %&gt; &lt;%: Html.LabelFor(model =&gt; model.ScoreFor) %&gt; &lt;%: Html.EditorFor(model =&gt; model.ScoreFor) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ScoreFor) %&gt; &lt;%: Html.LabelFor(model =&gt; model.ScoreAgainst) %&gt; &lt;%: Html.EditorFor(model =&gt; model.ScoreAgainst) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ScoreAgainst) %&gt; &lt;%: Html.LabelFor(model =&gt; model.Comments) %&gt; &lt;%: Html.DropDownListFor( model =&gt; model.Comments, (ViewData["CommentsList"] as SelectList) )%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Comments) %&gt; </code></pre> <p>The <code>&lt;div&gt;</code>s have been removed in the above.</p> <p>The call to edit the record displays the data OK including the correct choice for the dropdown lists. I make a few changes and the select the <code>Save</code> button. The correct POST event is called but the <code>Fixture fixture</code> parameter is null. ModelState is not valid and returns an error message of </p> <pre><code>The parameter conversion from type 'System.String' to type 'RLSBCWebSite.Domain.Entities.Fixture' failed because no type converter can convert between these types. </code></pre> <p>Why is fixture of type Fixture not being passed back correctly.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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