0

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) )%> &nbsp;<%= 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!

1 Answer 1

3
 <% Html.BeginForm("Submit", "Questionnaire", FormMethod.Post); %> 
 <input type="submit" name="submit" value="submit" />
 <% Html.EndForm(); %>

It looks to me like your form only has a single input inside 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?

<% Html.BeginForm("Submit", "Questionnaire", FormMethod.Post); %>
<%=ViewData["UserName"]%>
<%=Html.TextBox("test",ViewData["tt"])%>
<p />
<%:"Phone Number :"%>

<%=ViewData["PhoneNumber"]%>
<p />
<%
    foreach (var q in Model)
    {
        Html.RenderPartial("Question", q);
    }
%>
<input type="submit" name="submit" value="submit" />
<% Html.EndForm(); %>
Sign up to request clarification or add additional context in comments.

4 Comments

You are right, My form updated in the question , but when I included all of my editors in the form, post back is not fired, please check my updated question
To clarify, When I include all in one beginform, submit is not fired!
Thanks, When I do that, Submit action is not fired ( no post back happen )!
@Aboelnil: I have no idea why that would be the case. You might want to create another question showing the HTML that gets produced, and asking why clicking "Submit" isn't causing your browser to do a POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.