Parameter not passing from @Url.Action to method

94 Views Asked by At

I'm trying to pass a field value from my model via @Url.Action to a method in my controller but it continues to come through as null. The link I'm sending the field value from looks like this

<input type="button" value="Submit" 
       onclick="location.href='@Url.Action("NewName", "Home", new { name = Model.name})'" />

The method in the controller looks like this:

public ActionResult NewName(string name)
{
     // .   
     // .
}

Each time the value for name passed to the method is null. What am I missing?

1

There are 1 best solutions below

0
Rahul Sharma On BEST ANSWER

You can pass your value this way to the Controller:

<input type="button" value="Submit" onclick="location.href='@Url.Action("NewName", "Home")[email protected]';" />