在MVC中单击按钮后将参数传递给控制器 [英] Pass parameters to controller after button click in MVC

查看:389
本文介绍了在MVC中单击按钮后将参数传递给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我在MVC中创建一个应用程序,在VIEW中我有两个asp:TextBox和一个asp:Button。现在,我希望当我单击此按钮时,Textboxes值应该传递给controller.ie,会有一个click事件,其中值将被传递并保存到数据库。





我不知道在MVC中点击事件是如何工作的。



请朋友们帮助我。



提前致谢

Dear friends,

I am creating a application in MVC ,where in "VIEW" I have two asp:TextBox and a asp:Button. now, I want that when I click on this button the Textboxes values should passed to "controller".i.e, there will be a click event where values will be passed and saved to database.


I don't know how click event works in MVC.

Please friends help me .

Thanks in advance

推荐答案

MVC与ASP.NET Web Control不兼容。

我们只能使用HTML控件来支持MODEL - VIEW - CONTROLLER的流程。



您的解决方案:



在查看部分:



@using(Html.BeginForm(GetValue,Home))

{



< input id =Text1type =textname =txtOne/>

< input id = Button1type =submitvalue =button/>

}





In控制器Home==>动作GetValue..你得到TextBox值



MVC is not compatible with ASP.NET Web Control.
We can only use HTML Control to support the flow of the MODEL - VIEW - CONTROLLER.

Your Solution :

In the View Part:

@using (Html.BeginForm("GetValue","Home"))
{

<input id="Text1" type="text" name="txtOne"/>
<input id="Button1" type="submit" value="button" />
}


In the Controller "Home" == > Action "GetValue" .. You get the TextBox Value

[HttpPost]
       public ActionResult GetValue()
       {
           string textboxValue = Request.Form["txtOne"];
           //Code To Insert into the Database
           return View();
       }







这里[HttpPost]属性是必需的,因为我们发布了数据..另一种观点。




Here [HttpPost] attribute is required because We Posting the data.. to Another View.


这篇关于在MVC中单击按钮后将参数传递给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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