Ok guys, I need help!
Im working with an asp.net mvc3 razor (and I'm pretty new to this, but made a lot of web forms)
Ok so to the problem
My question revolves around presentation submission. I have a very complex model based on my view (strongly typed).
I want to return the model to the arguments of the HttpPost method of the controller. mostly:
public ActionResult Personal() { DataModel dataModel = new DataModel(); FormModel model = new FormModel(); model.candidateModel = dataModel.candidateModel; model.lookupModel = new LookupModel(); return View(model); } [HttpPost] public ActionResult Personal(FormModel formModel) { if (ModelState.IsValid) {
Now...
I'm having trouble getting the values ββin the formModel parameter of the post method.
This works (this means that I see this value), but it is tiring, since I need to write exactly where it sits in a row, each individual field:
@Html.TextBox("formModel.candidateModel.tblApplicant.FirstName", Model.candidateModel.tblApplicant.FirstName)
It looks like this:
<input name="formModel.candidateModel.tblApplicant.FirstName" id="formModel_candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/>
This does not work:
@Html.TextBoxFor(c => c.candidateModel.tblApplicant.FirstName)
It looks like this:
<input name="candidateModel.tblApplicant.FirstName" id="candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/>
Now I assume the problem is id id mismatch
So please answer me this:
- I think about it right.
- Why doesn't the text field get the correct / id value and how can I get it to get the correct / id value, so I can get it in POST (even if it's a problem)?
- Also, it looks like textboxfor is restrictive, as if you were using a date. How do you use the .toshortdate () method? This makes me think that the text box is not useful to me.
Quick clarification: when I say that textboxfor is not working, it gets values ββwhen I get the form. Therefore, they are filled, but in the POST / view I do not see them in the form Model in the parameters.
One more note:
None of the html helpers work, this is the problem. They also do not appear in modelstate.
Thank you all for your help.
Answer:
html.TextBoxFor and html.Textbox, POSTing values, model in parameters
This was a problem in my view somewhere, I replaced all the code with a fragment in this answer, and it worked.
Thanks again