MVC3 - 使用不同的区域局部视图 [英] mvc3 - using partial views in a different area

查看:327
本文介绍了MVC3 - 使用不同的区域局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于部分景色两个问题...


  1. 在使用部分视图VS @helper方法,我都用了
    互换并想获得更一致的
    用法。你们有什么呢?


  2. 你如何引用来自其他地区的局部视图。


我有一个区域名为admin和我在常规浏览目录的局部视图。我怎么使用它..我已经尝试它不工作,因为它不能找到以下内容。

  @ Html.Partial(VirtualPathUtility.ToAbsolute(〜/查看/ ControllerName / _PartialView),
 模型)

其他的我都试过 -

  @ Html.Partial(〜/查看/ ControllerName / _PartialView模型)


解决方案

我不知道,如果你的意思是HTML辅助,或剃刀助手当你说助手在任何情况下,我只创建HTML佣工当它是一个小,idividual项目等的控制。

如果你的意思是剃刀的帮手,那么他们在从局部模板不同,你可以给他们打电话之类的函数,传递你想要的任何参数。谐音很大程度上坚持的模范制度(当然温度/的ViewData /袋。

这是所有关于你想如何与code工作。

至于你的部分。你必须包括后缀。

  @ Html.Partial(〜/查看/ ControllerName / _PartialView.cshtml模型)

I have two questions regarding partial views...

  1. When to use Partial views vs @helper methods, i have used both interchangeably and would like to get more consistent in their usage. What do you guys do?

  2. How do you reference a partial view from another area.

I have an area called admin and i have a partial view in the regular Views directory. How do i use it .. i have tried the following which dont work as it cant be found.

@Html.Partial(VirtualPathUtility.ToAbsolute("~/Views/ControllerName/_PartialView"),
 Model)

other i have tried -

@Html.Partial("~/Views/ControllerName/_PartialView", Model)

解决方案

I'm not sure if you mean Html helpers, or razor helpers when you say "helpers" In any case, I only create Html helpers when it's a small, idividual item like a control.

If you mean Razor helpers, then they are different from Partials in that you can call them like functions, passing whatever parameters you want. Partials are largely stuck with the "model" system (and of course Temp/ViewData/Bag.

It's all about how you want to work with the code.

As for your Partial. You have to include the suffix.

@Html.Partial("~/Views/ControllerName/_PartialView.cshtml", Model)

这篇关于MVC3 - 使用不同的区域局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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