当前位置 : 主页 > 网络编程 > ASP >

asp.net-mvc – ASP.Net MVC“Magic Strings” – 可以避免吗?

来源:互联网 收集:自由互联 发布时间:2021-06-24
好的,请看下面这个例子: 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 RedirectToAc
好的,请看下面这个例子:

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");
}

在重定向到登录页面时,有没有避免“魔术字符串”?

在这种情况下,我不会接近MVC Futures.

我建议使用T4MVC

David Ebbo在这里谈到它:
http://blogs.msdn.com/davidebb/archive/2009/06/17/a-new-and-improved-asp-net-mvc-t4-template.aspx

此处的更新版本还包括对操作方法的重构支持:

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); %>

斯科特·汉塞尔曼(Scott Hanselman)在此发表了一篇博客:

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

网友评论