Archive for November, 2017

The MVC model is null when posting

I had an MVC view that I was using to update my data using a POST method by using a Bootstrap modal popup window. Everything seemed fine, but when I put a breakpoint in my controller action, my model was null. My very simple action:

       [HttpPost]
       public ActionResult Update(Coaster model) {
           return View();
       }

I’m going to give away the ending. The problem was that my form didn’t have the “name” property attached to the “input” tag. I thought the “id” property would be enough to send my model from the view to the controller, but it wasn’t. So instead of this:

<input type="text" id="Code" class="form-control" />

I had to have this:

<input type="text" id="Code" name="Coaster" class="form-control" />


		
Advertisements

Leave a comment