获得控制器的价值 [英] Getting value in controller

查看:73
本文介绍了获得控制器的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,



如果我用隐藏函数隐藏带有Jquery的div,当发布表单时如何获取文本框中的字段值控制器动作方法? div是隐藏的,但是当表单发布到action方法时我需要值。请帮助朋友。

Hello Friends,

If I hide a div with Jquery with hide function, how will I get the value of the fields inside it of textboxes when form is posted to controller action method? The div is hidden but I need the value when the form is posted to the action method. Kindly help friends.

推荐答案

您可以在前端使用div隐藏或显示页面中的控件,以便将数据发布到控制器,您可以使用隐藏字段这是永远不可见的。

You can use div in the front-end for hide or show controls within your page, for posting data to the controller you can use hidden fields which are never visible.
@using (Html.BeginForm("ControllerAction", "ControllerName", FormMethod.Post, new { @class  "form-horizontal container" }))
{
 @Html.TextBoxFor(x => x.ModelProperty,     //you can define the model field as hidden
      {
     new  @type = "hidden"
})	

//you can also define the field as hidden 
<input type="hidden" class="form-control" name="FieldName" id="FieldID" value="@Model.PropertyName" />			


//the button that will submit the form to the controller

<input type="submit" class="btn btn-success right" value="Submit" id="btnSubmit">
}



通过这种方式,隐藏字段将与其他字段一起提交给控制器。

注意:您也可以从表单中发布不受模型约束的数据,然后您需要将字段名称发送到控制器以获取数据。



希望这会有所帮助。


In this way the hidden fields will be submitted to controller along with other fields.
Note: you can also post data from the form which are not bounded to the model, then you need to send the field names to the controller to grab the data.

Hope this will help.


这篇关于获得控制器的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆