<a href="@(Html.MyActionHref(controllerName: "MyController", actionName: "MyAction"))">
The above line generates a hyperlink for Razor view. The html helper method MyActionHref() creates the link. On clicking the link it calls an action method from controller. Now suppose the action controller method which this link calls is parameterized i.e.public ActionResult MyAction(string myParams){}
(The html helper method MyActionHref() is even overloaded to accept three parameters accordingly.)
How this additional parameter can be passed to the controller action method from the model?
Say,
<a href="@(Html.MyActionHref(controllerName: "MyController", actionName: "MyAction",params: new {....} }))">
Any suggestions?
Why are you using such helper when you can simply:
@Html.ActionLink(
"some text",
"MyAction",
"MyController",
new { myParams = "Hello" },
null
)
which will generate the proper anchor tag:
<a href="/MyController/MyAction?myParams=Hello">some text</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With