我如何呈现MVC替代子视图? [英] How do I render an alternate child view in MVC?

查看:121
本文介绍了我如何呈现MVC替代子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC与工作,所以请不要认为我知道任何事情。

I'm new to working with MVC so please don't assume I know anything.

我拿起了很多已经写在MVC一个项目,我想有些东西添加到它。

I am picking up a project that has much already written in MVC and I am trying to add some things to it.

在View有一行

<% Html.RenderAction("List", "Image", new { id = Model.JobId, all = true });  %>

我看到的图像目录下的List.ascx。我看到的视图控制器上的列表方式。

I see a List.ascx under the Image directory. I see the List method on the view controller.

我想呈现列表方法的结果到不同的ascx文件。 (AssignImage.ascx)我知道我可以在控制器上添加另一种方法,但似乎我应该用同样的方法,但有不同的看法的一种方式。

I'd like to render the results of that list method to a different ascx file. (AssignImage.ascx) I realize I could add another method on the controller, but it seems like I should have a way of using the same method but a different view.

推荐答案

如果你不介意的重复使用(或复制)一些code我可能只是做一个新的行动来处理这个问题。

If you don't mind reusing (or duplicating) some code I'd probably just make a new action to deal with this.

我不认为我会改变行动的另一个参数来传递(动作已经正在采取2:和的jobId一个布尔值)。你可能会改变现有的code某处占了第三个参数。

I don't think I would change the action to pass in another parameter (the action already is taking 2: a jobId and a boolean). You'd probably have to change existing code somewhere to account for a third parameter.

假设动作只是给你一个记录列表我不明白如何与LINQ(或者不管你得到的数据)的一行添加一个新的动作会得罪干......特别是如果它使$ ç$ C更容易在一次操作中不混合太多的功能,以维护。如果其过于进攻,那么你就可以重构行动,调用一些常用的方法。

Assuming the action is just giving you a list of records I don't see how adding a new action with one line of LINQ (or however you are getting data) would offend the DRY... especially if it makes the code easier to maintain by not mixing too many functions in one action. If its too offensive, then you can refactor the actions to call some common method.

这篇关于我如何呈现MVC替代子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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