How can I use T4MVC with the external login confirmation form in the default MVC5 project?

StackOverflow https://stackoverflow.com/questions/21454306

Вопрос

In the default ASP.NET MVC 5 web project, the "Login" view ("Login.cshtml") has a BeginForm call like this:

@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

I'm trying to convert all my ActionLink, BeginForm (etc.) calls to use T4MVC, and so I changed it to:

@using (Html.BeginForm(MVC.Account.Login().AddRouteValue("ReturnUrl", (string)ViewBag.ReturnUrl), FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

...which worked fine.

However, there's another form in "ExternalLoginConfirmation.cshtml", which starts like this:

@using (Html.BeginForm("ExternalLoginConfirmation", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

I tried to use the same approach:

@using (Html.BeginForm(MVC.Account.ExternalLoginConfirmation().AddRouteValue(...)

...but the object returned by MVC.Account.ExternalLoginConfirmation has no AddRouteValue method.

I think this is because ExternalLoginConfirmation is an async action method that actually returns a Task<T> rather than just a T.

Is there any way I can get this to work with T4MVC, or do I simply need to leave this one alone? (I know I can just replace the magic strings using MVC.Account.ActionNames.ExternalLoginConfirmation and MVC.Account.Name), but it would be nice to be able to use the helper.

Это было полезно?

Решение

This is covered in this thread. Basically, try:

MVC.Account.ExternalLoginConfirmation().Result.AddRouteValue(...)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top