-1

I have found this code

<button type="button" class="btn btn-inverse btn-danger"
    onclick="@("window.location.href='" + @Url.Action("ActionName", "ControllerName") +"'");">
Link
</button> 

for redirecting- which is working fine, But now I need to pass parameter to this . Please help. Refereed the following How do I redirect a user when a button is clicked?

Sribin
  • 307
  • 4
  • 16
  • 1
    Possible duplicate of [URL.Action() including route values](https://stackoverflow.com/questions/19107061/url-action-including-route-values) – Albert Einstein May 18 '18 at 05:19

2 Answers2

3

@Sribin, below is fundamental which you can use,

your controller code will be,

 // GET: home
    public ActionResult Index()
    {
        User uObject = new User();
        uObject.FirstName = "abc";
        return View(uObject);
    }

    public ActionResult IndexTest(string id)
    {
        return View();
    }

your cshtml code will be

@model WebApplication2.Models.User
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<br />
<tr>
    <input type="button" onclick="SaveLookup()" value="submit" />

    <button type="button" class="btn btn-inverse btn-danger"
            onclick="@("window.location.href='" + @Url.Action("IndexTest", "Home", new {id = Model.FirstName}) +"'");">
        Link
    </button> 
</tr>

Instead of using model value you can grap value from view bag or any other tempdata too!!

Priyal Pithadiya
  • 889
  • 1
  • 5
  • 12
  • Thanks this is what I was looking for – Sribin May 18 '18 at 05:36
  • This is very basic fundamental of MVC. The initial learning steps so it might be happen they treat as a repeated query, common and unlogical question. Don't worry you are right to ask, if you are at learning stage :) – Priyal Pithadiya May 18 '18 at 05:41
0

@Sribin, Try with below,

<button type="button" class="btn btn-inverse btn-danger"
        onclick="@("window.location.href='" + @Url.Action("IndexTest", "Home", new {id = "ID"}) +"'");">
    Link
</button> 
Priyal Pithadiya
  • 889
  • 1
  • 5
  • 12