locked
Model state is valid but not updating the model RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I have a model ManageCountryModel, which I am trying to update.

    This model i having some properties and all have values, but it is not updating

    public ActionResult Edit(ManageCountryModel MCMO, string myListBox1, string myListBox1Values, string myListBox2, string myListBox2Values)
    {
    try
    {
    if (ModelState.IsValid)
    {
    
    DataAccessLayer objDB = new DataAccessLayer();
    objDB.ManageCounty_Update(MCMO);
    int CountryId = 0;
    CountryId = Convert.ToInt32(MCMO.id);
    AssignModules(myListBox2, myListBox2Values, CountryId);
    UnAssignModules(myListBox1, myListBox1Values, CountryId);
    
    }
    
    return View("Index");
    }
    catch (Exception ex)
    {
    throw;
    }
    }

    Untitled

    Even I did not get any error. But yes in my model there is a property 

     public List<ModuleModel> MyModules { get; set; }

    Which I use on condition based. When I don't use it it remains null. But I don't think just because it is null my model is not getting update.

    Please suggest.

    Friday, July 19, 2019 3:21 AM

Answers

  • User1052662409 posted

    You could post more details,such as:your model and your view,so that I can reproduce your issue.

    Thanks Yuki for responding. The issue is resolved, it was my (silly) mistake. By mistake I was converting an int to bool in my  data access layer.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 20, 2019 5:49 AM

All replies

  • User1520731567 posted

    Hi demoninside9,

    Controller get value from html tags' name.

    What is your ManageCountryModel?

    Is it a ViewModel or DTO model?

    You could post more details,such as:your model and your view,so that I can reproduce your issue.

    Best Regards.

    Yuki Tao

    Friday, July 19, 2019 6:06 AM
  • User-1038772411 posted

    Hello, demoninside9

    For my undertanding after seen code if your model retrun null than some required field and foreign key value (if exists your database) also null, so at that time your updation will not be completed kindly please check it once your fields and data.

    Thanks.

    Friday, July 19, 2019 6:09 AM
  • User1052662409 posted

    You could post more details,such as:your model and your view,so that I can reproduce your issue.

    Thanks Yuki for responding. The issue is resolved, it was my (silly) mistake. By mistake I was converting an int to bool in my  data access layer.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 20, 2019 5:49 AM