加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:14:32 所属栏目:asp.Net 来源:网络整理
导读:好的,请看下面这个例子: 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("Main
好的,请看下面这个例子:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读