如何从ASP.NET中的控制器将数据传递到布局页面 [英] How to pass data to layout page from controller in ASP.NET

查看:59
本文介绍了如何从ASP.NET中的控制器将数据传递到布局页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用动态菜单栏的布局页面,因为我从控制器传递ilist对象,它将动态值绑定到菜单栏。模态类名称是菜单栏。



现在我在员工视图中使用此布局为菜单栏,现在我想将动态值绑定到下拉列表,模态类名称是员工。我正在通过员工对象查看。



现在我收到错误对象应该是菜单栏类型



如果在视图中我写了

@ {

layout = null

}



然后页面和下拉列表工作,布局页面不显示。



我尝试过:



i am having layout page with dynamic menubar for that i am passing ilist object from controller , which bind dynamic value to menubar. modal class name is menubar.

now i am using this layout in employee view for menubar, now i want to bind dynamic values to dropdown ,modal class name is employee .for which i am passing employee object to view.

now i am getting error "object should be of menubar type"

if in view i write
@{
layout =null
}

then pages and dropdown works ,layout pages dont appear.

What I have tried:

i am having layout page with dynamic menubar for that i am passing ilist object from controller , which bind dynamic value to menubar. modal class name is menubar.

now i am using this layout in employee view for menubar,  now i want to bind dynamic values to dropdown ,modal class name is employee .for which i am passing employee object to view.

now i am getting error "object should be of menubar type"

if in view i write 
@{ 
layout =null
}

then pages and dropdown works ,layout pages dont appear.

推荐答案

如果你想通过从控制器到视图页面的对象列表,您可以使用此代码。

If you want to pass list of object from controller to view page, you can use this code.
public ActionResult Method()
{
  List<MyObject> list = new List<MyObject>();
  return PartialView(list);
}


//view
@model List<MyObject>


这篇关于如何从ASP.NET中的控制器将数据传递到布局页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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