ASP.Net MVC Magic Strings - Can You Always Avoid Them?

Ok, take this example below,

public ActionResult ViewProfile()
        {
            //Load the profile for the currently logged in user
            if (Membership.GetUser() != null)
            {
               //Do some stuff get some data.

                return View(ReturnViewModel);
            }

            return RedirectToAction("MainLogon","Logon");
        }

In any case, to avoid the "magic lines" when redirecting to the login page?

+3
source share
2 answers

In this case, I will not approach MVC Futures.

I would recommend using T4MVC

David Ebbo talks about it here: http://blogs.msdn.com/davidebb/archive/2009/06/17/a-new-and-improved-asp-net-mvc-t4-template.aspx

With the updated version, it also includes refactoring support for action methods:

http://blogs.msdn.com/davidebb/archive/2009/06/26/the-mvc-t4-template-is-now-up-on-codeplex-and-it-does-change-your-code- a-bit.aspx

, :

<% Html.RenderPartial("DinnerForm"); %>

intellisense :

<% Html.RenderPartial(MVC.Dinners.Views.DinnerForm); %>

:

http://www.hanselman.com/blog/TheWeeklySourceCode43ASPNETMVCAndT4AndNerdDinner.aspx

+11

(1). . - ASP.NET MVC, MVC Futures

- :

Html.ActionLink<HomeController>(c => c.Index(), "Home")

(2). .

+1

Source: https://habr.com/ru/post/1722666/


All Articles