Using Asp.net MVC, I have one view that’s strongly bind to “List” , and loop to partial render a partial view as following
<%
foreach (var q in Model)
{
Html.RenderPartial("Question", q);
}
%>
and this partial view strongly bind to “Question”
<%
foreach (var option in Model.Options)
{
%>
<p/>
<%=Html.RadioButton(option.QuestionId.ToString(), (option.IsSelected) )%> <%= option.OptionBody%>
<%
}
}
%>
Do a post back in the master view as following
<% Html.BeginForm("Submit", "Questionnaire", FormMethod.Post); %>
<input type="submit" name="submit" value="submit" />
<% Html.EndForm(); %>
Finally at my controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Submit(List<Question> test)
{
var x = test;
return View("Submit");
}
My Form is
<% Html.BeginForm(); %>
<%:"UserName : "%>
<%=ViewData["UserName"]%>
<%=Html.TextBox("test",ViewData["tt"])%>
<p />
<%:"Phone Number :"%>
<%=ViewData["PhoneNumber"]%>
<p />
<%
foreach (var q in Model)
{
Html.RenderPartial("Question", q);
}
%>
<% Html.EndForm(); %>
<% Html.BeginForm("Submit", "Questionnaire", FormMethod.Post); %>
<% TempData["form"] = ViewData;%>
<input type="submit" name="submit" value="submit" />
<% Html.EndForm(); %>
and when I include all in one begin form, post back dosn’t fire”
My Question is
Why x is always null?
and how can I get my updated model ( having user selection to the radio button rendered in the partial view )
Should I use TempData to store my value? and how ?
After receiving the right updated model, i will save it to DB.
Thanks!
It looks to me like your form only has a single
inputinside of it. You need to render your editors inside the form, or they will not get included as part of the POST.Update
So now you’ve got two forms: one has the inputs you want to submit and the other one has the actual button. The problem is, clicking the submit button on the second one will only submit the second (practically empty) form. Why not combine your forms?