传递HTML文本框的值作为参数传递给控制器​​的方法在asp.net MVC [英] Passing html textbox value as a parameter to controllers method in asp.net MVC

查看:239
本文介绍了传递HTML文本框的值作为参数传递给控制器​​的方法在asp.net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在 Html.Textbox 值传递给从锚标记控制器,这样我就可以搜索传递给控制器​​的值。请告诉我怎样才能做到这一点。

 < A HREF =@ Url.Action(指数,家,新{})> @ P< / A>公众的ActionResult指数(string字符串)
        {
        }@ Html.TextBox(字符串)


解决方案

使用jQuery

  @ Html.TextBox(字符串,空,新的{@类=txtString})
< A HREF =@ Url.Action(指数,家,新{})级=linkAction> @ P< / A>

然后在您的脚本

  $('。txtString')。在('模糊',函数(){
    $('。linkAction')。ATTR('src'中,'@ Url.Action(指数,家,新的{text =----})'。替换(---- ,$('txtString。')VAL()))。
});

I want to pass the Html.Textbox value to a controller from anchor tag, so that I can search the value passed to a controller. Please tell me how can I achieve this.

<a  href="@Url.Action("Index", "Home", new {  })">@p</a>

public ActionResult Index(string String)
        {


        }

@Html.TextBox("String")

解决方案

use jquery

@Html.TextBox("String", null, new { @class="txtString" })
<a  href="@Url.Action("Index", "Home", new {  })" class="linkAction">@p</a>

then in your script

$('.txtString').on('blur', function(){
    $('.linkAction').attr('src', '@Url.Action("Index", "Home", new { text = "----" })'.replace("----", $('.txtString').val()));
});

这篇关于传递HTML文本框的值作为参数传递给控制器​​的方法在asp.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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