Home > Mobile >  How to do a dynamic href below?
How to do a dynamic href below?

Time:04-13

How to do dynamic href below?

@Model.inbox_type is a dynamic value either "1", "2", "3" .. "6", how to apply it with href below?

<button  type="button" onclick="location.href='@Url.Action("Index/"   "@Model.inbox_type" , "Inbox")'">Exit</button>

CodePudding user response:

You can pass a parameter on Url.Action instead of string appending

<button  type="button" onclick="location.href='@Url.Action("Index", "Inbox", new { id: @Model.inbox_type })'">Exit</button>

Note that id is the parameter you're expecting in the action function

public ActionResult Index(string id) 

You can check this document for a reference

  • Related