使用MVC 3 Razor Framework加载动态菜单 [英] loadind dynamic menu using MVC 3 Razor Framework

查看:52
本文介绍了使用MVC 3 Razor Framework加载动态菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是使用razor的mvc新手所以我需要有关动态菜单加载的帮助。我的当前流程是这样的,在母版页上会有登录按钮或点击一个登录对话框打开的布局页面和成功提交用户登录和某些
链接可见它。我想使用razor在MVC中创建相同的功能。为此我创建了一个布局页面像这样


  < div class =" topheader">

        < div id =" topheader">


 < div id =" login">

      ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; @RenderSection(" login",required:false)


< / div>


< / div>


< / div>


< div>


  @RenderBody()


< / div>


< div class =" footer" />


现在我创建了一个控制器类调用home和Model类调用User(emailid,password).Follwing是我对index.cshtml的视图的代码


@model Storybrick.Models.MemberInfoModel

@ {

    ViewBag.Title =" Home"; $
 

}


@section login

{

  @ *这里我写了逻辑根据用户成功登录动态加载菜单* @


}


现在这个东西有效,但有一个重复的问题,即我必须复制这个每页都有相同的代码。所以我可以实现这个目标。



谢谢,


Krutik




解决方案

请在
http://forums.asp.net
论坛上发布ASP.NET问题

hi,

I am new to mvc using razor so i need help regarding dynamic menu load.My current flow is like this there would be login button on master page or layout page on click of that a login dialog get opened and on successful submission user get login and certain links get visible with it.I want to create same functionality in MVC using razor.For that i I have created a layout page like this

  <div class="topheader">
        <div id="topheader">

 <div id="login">
                            @RenderSection("login", required: false)

</div>

</div>

</div>

<div>

 @RenderBody()

</div>

<div class="footer" />

Now i have created a controller class call home and Model class call User(emailid,password).Follwing is code of view of my view for index.cshtml

@model Storybrick.Models.MemberInfoModel
@{
    ViewBag.Title = "Home";
 
}

@section login
{
 @* here i have written logic for loading menu dynamically based on user successful login*@

}

Now this stuff work but there is one problem of duplication i.e. i have to copy this same code on each page.So is there anyother approach i can achieve this.

Thanks,

Krutik

解决方案

Please post ASP.NET questions on the forums at http://forums.asp.net


这篇关于使用MVC 3 Razor Framework加载动态菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆