如何将Html元素的text / Value从视图传递给控制器 [英] How to pass the text/Value of an Html element from view to controller

查看:53
本文介绍了如何将Html元素的text / Value从视图传递给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问控制器中按钮的值,然后将其传递给视图。但是从视图传递到控制器的str的值为null。



I want to access the value of button in controller and then pass it to the view as well. But the value of "str" passed from view to controller is null.

@{
     var str = "Shoes";
  }







      <a href="~/Home/Products_By_Category/@str" target="_parent">
                <input type="button" value="Shoes" class="btn"/>
      </a>

<pre lang="c#">

     public ActionResult Products_By_Category(string s)
     {
           ViewBag.category = s;
           return View();
     }

推荐答案

如下更改按钮

Change your button like below
<input type="button" name="button" value="Shoes" class="btn" />



您还需要将参数更改为 st铃声按钮


Also you need to change the parameter to string button

public ActionResult Products_By_Category(string button)



希望这会有帮助


Hope this helps


始终将控制传递的名称作为参数传递给操作方法
Always pass name of the control pass as parameter in action method


嘿,



有可能这样......



Hey,

It is possible in this way...

<a href="@Url.Action("Products_By_Category","Home",new{s=@str})" target="_parent">
                <input type="button" value="Shoes" class="btn"/>
      </a>





< br $> b $ b

确定,这会起作用并帮助你。 :)





--SDK





Dam sure, this will work and help you. :)


--SDK


这篇关于如何将Html元素的text / Value从视图传递给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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