开发者

how i can got the value who are define n times in the form in ASP.NET MVC?

i have a form where user fill the n time a information using add another textbox and fill them.

i put the name them as

textbox_1
textbox_2

now how i can got all form valu开发者_C百科es who are start with textbox_1. any idea to do it in asp.net mvc


you can get the value of this text box using javascript and save it in hidden field as comma separated then read the hidden field value from your action method(I am using jquery)

var AllTextBoxesInPage = $('input[type=text]');
var AllValues='';
AllTextBoxesInPage.each(function(index){
   if(index==0)
   {
    AllValues+=',';  
   }
   AllValues+=$(this).val();
});
$('#HiddenFieldID').val(AllValues);

in your controller class

public ActionResult MyAction(FormCollection MyForm)
{
   String AllValues =MyForm["HiddenFieldName"];
   String[] SeparatedValuse = AllValues.Split(",");
}


Alternatively, you can use BeginCollection from steve sanderson and optionally you can have a look at master detail form

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜