形式收集问题 [英] Form Collection issue
问题描述
我有一个HTML开始MVC格式
I have an html begin form in mvc
@using (Html.BeginForm("Search", "Reports",FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-inline" }))
{
<div class="form-group">
<input type="text" class="form-control input-sm" placeholder="Value" name="SearchValue">
<input type="text" class="form-control input-sm second-value" placeholder="Value" style="display:none;" name="SearchValue1">
<button type="button" class="btn btn-default btn-Add">+</button>
</div>
<div id="othersearch"></div>
<input type="submit" value="Search" class="btn btn-primary" />
}
我想在一个控制器张贴这种形式的项目
I want to post this form item in one controller
public ActionResult Search(FormCollection collection)
{
string searchvalue = collection.Get("SearchValue");
return View();
}
我的问题是,有些时候第二个文本框是不可见的..这一次我不想收集values.And当我preSS按钮添加生成具有相同名称的形式相同类型的输入域(我可以添加许多输入框)。那么,我怎么能收集所有这些在我的控制器。请帮我..
my problem is that some times second text box is not visible.. that time i dont want to collect the values.And when i press button add generate the same type of input field in the form with same name (i can add many input box). Then how can i collect all these in my controller . please help me..
推荐答案
您可以在你的情况下,所有具有相同名称的SeachValue的文本框中。
You can have all the text boxes with same name "SeachValue" in your case.
字符串searchvalue = collection.Get(SearchValue);
这将返回所有文本框值逗号saperated字符串,那么可以拆分,并进一步使用。
This will return all text box values as comma saperated string which you can split and use further.
退房的屏幕截图
Check out the screen shot
在HTML
和结果
这篇关于形式收集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!