locked
drop down bind in mvc edit view RRS feed

  • Question

  • User616860969 posted

    DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'ClaimStatus'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'Status'.

    <div class="col-md-6">
    @Html.LabelFor(model => model.ClaimStatus, htmlAttributes: new { @class = "control-label " })
    @Html.DropDownList("Statusitem", (IEnumerable<SelectListItem>)ViewBag.Statusitem, new { id = "ddlStatus", @class = "form-control" })
    @Html.ValidationMessageFor(model => model.ClaimStatus, "", new { @class = "text-danger" })
    </div>

    using (var dbctx = new myDbContext())
    {

    var data = dbctx.SearchInfo.Where(m => m.HS_ID == Id).FirstOrDefault();


    string Statusselected = dbctx.Claims.Where(m => m.ID== Id).Select(m => m.Status).FirstOrDefault();


    ViewBag.Statusitem = new SelectList(PopulateStatus(), "Status", "Description", Statusselected);




    return View(data);
    }

    how to reslove this issues?

    Thursday, November 16, 2017 1:37 PM

Answers

  • User-832373396 posted

    <g class="gr_ gr_45 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="45" data-gr-id="45">Hi</g> <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="8" data-gr-id="8">sanjay</g>,

    Sir, I am trying to reproduce your question.

    Please check the difference in your code.

    here is the working testing example:

    (note: make sure that "Status" is the property of PopulateStatus() collection)

     public class mymodel {
                public string Status { get; set; }
                public string Description { get; set; }
            }
            public class mymodel2
            {
                public string ClaimStatus { get; set; }     
            }
            
            public ActionResult Index1() {
                ViewBag.Statusitem = new SelectList(new List<mymodel>{ new mymodel { Status= "Status1", Description= "Description1" },
                new mymodel { Status= "Status2", Description= "Description2" } }, "Status", "Description","Status2");
                return View();
            }

    and at the page:

    @{
        ViewBag.Title = "Index1";
    }
    @model  mymodel2
     
    
    @Html.LabelFor(model => model.ClaimStatus, htmlAttributes: new { @class = "control-label " })
    @Html.DropDownList("Statusitem", (IEnumerable<SelectListItem>)ViewBag.Statusitem, new { id = "ddlStatus", @class = "form-control" })
    @Html.ValidationMessageFor(model => model.ClaimStatus, "", new { @class = "text-danger" })
      

    Please let me know if still any question:)

    With regards, Angelina Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 17, 2017 7:06 AM

All replies

  • User475983607 posted

    DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'ClaimStatus'.

    The error is telling you that the model does not have a property named ClaimStatus.

    @Html.ValidationMessageFor(model => model.ClaimStatus, "", new { @class = "text-danger" })

    how to reslove this issues?

    You'll need to review your code or post all the relevant bits as there is not enough information in the code snippet to provide an accurate solution.

    Thursday, November 16, 2017 2:20 PM
  • User-832373396 posted

    <g class="gr_ gr_45 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="45" data-gr-id="45">Hi</g> <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="8" data-gr-id="8">sanjay</g>,

    Sir, I am trying to reproduce your question.

    Please check the difference in your code.

    here is the working testing example:

    (note: make sure that "Status" is the property of PopulateStatus() collection)

     public class mymodel {
                public string Status { get; set; }
                public string Description { get; set; }
            }
            public class mymodel2
            {
                public string ClaimStatus { get; set; }     
            }
            
            public ActionResult Index1() {
                ViewBag.Statusitem = new SelectList(new List<mymodel>{ new mymodel { Status= "Status1", Description= "Description1" },
                new mymodel { Status= "Status2", Description= "Description2" } }, "Status", "Description","Status2");
                return View();
            }

    and at the page:

    @{
        ViewBag.Title = "Index1";
    }
    @model  mymodel2
     
    
    @Html.LabelFor(model => model.ClaimStatus, htmlAttributes: new { @class = "control-label " })
    @Html.DropDownList("Statusitem", (IEnumerable<SelectListItem>)ViewBag.Statusitem, new { id = "ddlStatus", @class = "form-control" })
    @Html.ValidationMessageFor(model => model.ClaimStatus, "", new { @class = "text-danger" })
      

    Please let me know if still any question:)

    With regards, Angelina Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 17, 2017 7:06 AM
  • User616860969 posted

    Thank you ,its work 

    Friday, November 17, 2017 9:40 AM