开发者

ASP.NET MVC: Display a link to another action

开发者 https://www.devze.com 2023-02-05 23:59 出处:网络
@Html.ActionLink(\"Add a bill\", \"Create\", new { controller = \"Bill\"}); This is the code I used to add an link to Create method in Bill controller.
@Html.ActionLink("Add a bill", "Create", new { controller = "Bill"});

This is the code I used to add an link to Create method in Bill controller.

But in the view I saw

Add a bill (/Bi开发者_JAVA技巧ll/Create):

So, how can I remove the brackets? (/Bill/Create).

And, I also want this link to act as a button instead of a , how can I do that? Thanks for your help.


It is strange what brackets you are talking about. Assuming the default routes both:

@Html.ActionLink("Add a bill", "Create", new { controller = "Bill" })

and:

@Html.ActionLink("Add a bill", "Create", "Bill")

are equivalent and should generate the following markup:

<a href="/Bill/Create">Add a bill</a>

As far as your question about the button is concerned you could use a form:

@using (Html.BeginForm("Create", "Bill"))
{
   <input type="submit" value="Add a bill" />
}
0

精彩评论

暂无评论...
验证码 换一张
取 消