using formcollection to retrieve a string of a repetitive dropdownlist and textfield from mvc3 view

StackOverflow https://stackoverflow.com/questions/12787763

  •  06-07-2021
  •  | 
  •  

Question

I need help to create and retrieve a repetitive selected dropdownlist values and their corresponding input decimal values from mvc3 view into controller.

I have paycat in dropdownlist and a corresponding payamount(decimal) in an input textbox in MVC3 view. I am looking for a way to get strings of selected category and corresponding payamount and commit these to database in controller. I have tried to use in the view

 @for ( var i = 0; i <4 2; i++) {

   <div class="editor-label">
        @Html.LabelFor(model => model.PId, "PayCat")
    </div>

        <div class="editor-field">
    @Html.DropDownList("PId", String.Empty)
      </div>

     <div class="editor-label">
        @Html.LabelFor(model => model.Pay)
    </div> 
      <div class="editor-field">
         @Html.EditorFor(model => model.Pay)
         }

But I do not know where to put indexing variable [i] for the code to run. Any help will be appreciated thanks

Was it helpful?

Solution

I have resorted to use a dynamic approach with the help of jquery-dynamic form script. I add the fields dynamically when needed and manipulate the entries using form collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top