ASP.NET,将数据从视图发送到控制器

时间:2017-01-09 14:54:13

标签: jquery asp.net-mvc view controller

我想将视图中的数据发送到控制器。我做了如下所示,但值为null。 使用jquery,我创建动态字段并自动对其中的数据求和。  我想在附加中发送输入文本数据。 我怎么能这样做?

我的Jquery代码:

$(Wrapper).append('\
        <div>\
        <input type="text" class="register_input span3"\
        name="value" + Count +'" id="value' + Count + '"\
        placeholder="Enter the value" style="margin:0px 15px 20px 0px"/>\</div>');) 



 @using (Html.BeginForm("Example", "Example", FormMethod.Post .....)
{
       ...
    input type="submit" value="save" id="save" 

}

我的控制器:

[HttpPost]  
public ActionResult Example(String value )
{  
     string a = value;  
     //a is null  ......

}

2 个答案:

答案 0 :(得分:0)

<input /> html元素必须嵌套在<form></form>元素中才能使其生效,因为当您单击<input type="submit" />按钮时,它实际上已经传递了<form>元素及其内容作为请求。所以你应该通过jquery将它附加到表单中。所以基本上不是

$(Wrapper).append(...) 

使用

$("form").append(...)

或者给表单提供一个id,所以你只需要定位那个特定的表单元素。

答案 1 :(得分:0)

参数字符串必须是(值+计数)

for row in soup.select("table[summary=formatting] tr"):
    # ...