001
001

Reputation: 65155

How to get input parameter in Razor?

Example

When editing item

/domain.com/app/item/detail/111     
OR
/domain.com/app/item/detail/?Id=111 

When creating a new item

/domain.com/app/item/detail/new
OR
/domain.com/app/item/detail/

Upvotes: 0

Views: 1800

Answers (2)

Farhad Bagherlo
Farhad Bagherlo

Reputation: 6699

You can use the following:

Request.Params["paramName"]

Upvotes: 1

Matthieu Charbonnier
Matthieu Charbonnier

Reputation: 2982

You can access query strings like this

@if(Request.QueryString["Id"] == "111")
{
    <div>foo bar</div>
}

or

use ViewBag in your controller to give the information to the view

public ActionResult Detail(string Id)
{
    ViewBag.Id = Id;

    return View();
}

Then in your view

<div>@ViewBag.Id</div>

Upvotes: 3

Related Questions