asp.net-mvct4mvc

Convert ActionLink to T4MVC ActionLink


Probably it should be very easy but I am not sure that I did it correctly, so I want to ask you how to convert the code below to T4MVC syntax:

@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new {id = "loginLink"})

I tried to do this code and it works fine but I am not sure I did it 100% correct.

@Html.ActionLink("Log in", MVC.Account.Login(null, null), htmlAttributes: new { id = "loginLink" })

The Login method signature is:

public virtual async Task<ActionResult> Login(LoginViewModel model, string returnUrl)

Thanks in advance.


Solution

  • Based on this example:


    @Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)
    

    being transformed into this:

    @Html.ActionLink("Delete Dinner", MVC.Dinners.Delete(Model.DinnerID))
    

    Your implementation of ActionLink using T4MVC seems correct.

    You include your link text - Log in

    You include your Controller - Account

    You include your Action Name/Method with parameters - Login(null, null)

    The only thing that I can't find is the correct way to implement htmlAttributes but I was able to find this example. You might not even need to put htmlAttributes: new { id = "loginLink" }.. instead just try new { id = "loginLink" } and take out the htmlAttributes.

    I hope this helps!