Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
@{
     var str = "Shoes";
  }


HTML
      <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();
     }
Posted
Updated 17-Sep-13 19:30pm
v3
Comments
[no name] 18-Sep-13 1:40am    
use FormCollection

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

Also you need to change the parameter to string button
public ActionResult Products_By_Category(string button)

Hope this helps
 
Share this answer
 
Always pass name of the control pass as parameter in action method
 
Share this answer
 
Hey,

It is possible in this way...

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




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


--SDK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900