3

I have a problem when trying to render multiple models in a view.

Lets say that I have:

Model

public int ID { get; set; }
public ArrayOfThings[] Things { get; set; }

View

for (int i = 0; Model.Things.Count() > i; i++)
{
    using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { Id = i }))
    {
        <p>@Html.CheckBoxFor(m => m.Things[i].IsDone, "Some Check")</p>

        <input type="submit" title="Delete" value="Check as Done" name="btn_submit" />
    }
}

How would I do this so that the input (submit) button would correlate with the right form? As it is, only the first form is being affected.

BryanH
  • 5,826
  • 3
  • 34
  • 47
Lee Booker
  • 61
  • 2
  • 6
  • Thanks, but that doesn't seem to work – Lee Booker May 21 '13 at 15:52
  • See [this question from Friday](http://stackoverflow.com/questions/16613519/mvc-multiple-forms-in-partialview-returns-null-on-postback-for-except-the-1st-on/16614614#16614614). Unfortunately, I currently don't know how to make this work with multiple forms, but that should give you a starting point. – Jason Berkan May 21 '13 at 15:59
  • Check these posts: - [ASP.NET MVC 3 Multiple Submit Inputs in One Form][1] - [How do you handle multiple submit buttons in ASP.NET MVC Framework?][2] [1]: http://stackoverflow.com/questions/8258750/asp-net-mvc-3-multiple-submit-inputs-in-one-form [2]: http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework – Dmitry Pavlov May 21 '13 at 16:55
  • It is not clear from your question whether you have multiple forms or a single form. Also it is not clear what model do you want to be posted to the server when this form is submitted. Also why are you setting the `id` to the index of the loop? – Darin Dimitrov May 22 '13 at 06:14
  • be sure you don't have nested forms. and what are you posting? you don't have something like `@Html.HiddenFor(m=>m.Things[i].Id)` inside the form. – RinatG May 23 '13 at 10:12

1 Answers1

0

I think that maybe you need to change your mind. why you are creating new form?? you can use action link instead of submit button and send data through ActionLink parameters.

  <%=Html.ActionLink("Link Text", "Action", "Controller", new {id = "1"}, null)%>
Mostafa Soghandi
  • 1,524
  • 1
  • 12
  • 20