C# 如何在ASP MVC和实体框架中访问其他控制器的视图
我正在使用C和SQLServer2005开发一个ASP.NETMVC3应用程序 我还使用实体框架和代码优先方法 我有一个视图索引,它是使用实体框架自动生成的,其他视图在一个文件夹中创建、编辑、删除 这些视图的文件夹名称为“ProfileGa”,填充其文件夹的控制器为“ProfileGaController”,模型为“FlowViewModel” 我的问题是我想从“ProfileGaController”的视图索引访问其他控制器的视图 要进一步解释: 那么,我如何通过一个动作链接从Profile_Ga precisy Index的角度访问Gamme的视图呢 我将把索引的代码放在下面:C# 如何在ASP MVC和实体框架中访问其他控制器的视图,c#,visual-studio-2010,asp.net-mvc-3,entity-framework,C#,Visual Studio 2010,Asp.net Mvc 3,Entity Framework,我正在使用C和SQLServer2005开发一个ASP.NETMVC3应用程序 我还使用实体框架和代码优先方法 我有一个视图索引,它是使用实体框架自动生成的,其他视图在一个文件夹中创建、编辑、删除 这些视图的文件夹名称为“ProfileGa”,填充其文件夹的控制器为“ProfileGaController”,模型为“FlowViewModel” 我的问题是我想从“ProfileGaController”的视图索引访问其他控制器的视图 要进一步解释: 那么,我如何通过一个动作链接从Profile
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.FlowViewModel>" %>
<%@ Import Namespace="Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Gestion de flux de production</h2>
<p>
<%: Html.ActionLink("Ajouter une nouvelle gamme", "Create") %>
</p>
<table>
<tr>
<th>
ID Gamme
</th>
<th>
Entrée
</th>
<th>
Sortie
</th>
<th>
Gamme Suivante
</th>
<th>
Etat
</th>
<th>Opérations</th>
</tr>
<% foreach (var item in Model.Profile_GaItems) { %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.ID_Gamme) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.In_Ga) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Out_Ga) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Next_Gamme) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Etat) %>
</td>
<td>
<%: Html.ActionLink("Modifier", "Edit", new { id=item.ID_Gamme }) %> |
<%: Html.ActionLink("Détails", "Details", new { id=item.ID_Gamme }) %> |
<%: Html.ActionLink("Supprimer", "Delete", new { id=item.ID_Gamme }) %>
</td>
</tr>
<% } %>
</table>
<% using (Html.BeginForm("Save", "ProfileGa"))
{ %>
<div><%:Html.Label("Gamme :")%><%: Html.DropDownListFor(model => model.SelectedProfile_Ga, new SelectList(Model.Profile_GaItems, "ID_Gamme", "ID_Gamme"))%> <input type="button" value="Configurer" id="btnShowGestion" /></div>
<div id="divGestion"><%: Html.Partial("Gestion", Model) %></div>
<% } %>
<script type="text/javascript">
$(document).ready(function () {
$('#btnShowGestion').click(function () { $('#divGestion').slideToggle("slow") });
});
</script>
<fieldset>
<legend>Gestion des Gammes</legend>
<table>
<tr>
<th>
ID Gamme
</th>
<th>
ID Poste
</th>
<th>
Nombre de Passage
</th>
<th>
Position
</th>
<th>
Poste Précédent
</th>
<th>
Poste Suivant
</th>
<th>Opérations</th>
</tr>
<% foreach (var item in Model.GaItems) { %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.ID_Gamme) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.ID_Poste) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Nbr_Passage) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Position) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Last_Posts) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Next_Posts) %>
</td>
<td>
<%: Html.ActionLink(?????????????????) %> |
<%: Html.ActionLink(?????????????????) %> |
<%: Html.ActionLink(?????????????????) %>
</td>
</tr>
<% } %>
</table>
</fieldset>
</asp:Content>
注:
ActionLink中的“??”是我想要访问Gamme视图的地方。这是ActionLink扩展方法的签名之一: 第三个参数controllerName是您在这里想要的 因此,在你的情况下:
Html.ActionLink("Modifier", "Edit", "Gamme" new { id=item.ID_Gamme })
您还提到,您“想要访问另一个控制器的视图”,这与ActionLink方法并不完全相关,该方法只需发出一个带有适当Url的标记链接,该链接将加载请求的[Controller.Action]。这是ActionLink扩展方法的签名之一: 第三个参数controllerName是您在这里想要的 因此,在你的情况下:
Html.ActionLink("Modifier", "Edit", "Gamme" new { id=item.ID_Gamme })
您还提到您“想要访问另一个控制器的视图”,这并不完全是ActionLink方法的目的,该方法只需发出一个带有适当Url的标记链接,该链接将加载请求的[Controller.Action]。如果您愿意,也可以从控制器而不是Url执行此操作 在action方法中使用这行代码
返回viewName,model如果愿意,您也可以从控制器(而不是URL)执行此操作 在action方法中使用这行代码
return ViewViewName,modelthx但是这个链接让我看到了Profile_Ga的编辑,这意味着这个:Html.ActionLinkModifier,Edit,Gamme new{id=item.id_Gamme}和这个:我看到了你的编辑,,,所以我不能使用ActionLink访问另一个控制器,那么解决方案是什么呢,,,我想把我带到控制器“GammeController”文件夹“Gamme”中的视图“Edit”,也许我搞错了。但是,在MVC中,视图并不意味着可以直接访问,只能使用操作。请阅读我答案中的最后一段,或者阅读更多关于MVC框架如何工作的内容。是的,我读了,,,我现在需要一种方法,我如何将一个链接放到控制器“Gamme”的编辑视图中,这是可能的吗?thx但是该链接将我带到Profile_Ga的编辑,这意味着这两者之间没有区别:Html.ActionLinkModifier,Edit,Gamme new{id=item.id\u Gamme}这是:我看到了您的编辑,,,所以我不能使用ActionLink访问另一个控制器,,,那么解决方案是什么?对不起,,,我想让我看到控制器“GammeController”文件夹“Gamme”中的视图“edit”,也许我搞错了。但是,在MVC中,视图并不意味着可以直接访问,只能使用操作。请阅读我的答案中的最后一段,或者阅读更多关于MVC框架如何工作的内容。是的,我读了,,,我现在需要一种方法,我如何放置一个指向控制器“Gamme”编辑视图的链接,这是可能的吗?那么第一个问题将是你的答案:我为该控制器创建了一个新视图,,,但我有一些空值问题,,,等等,我会给你新问题的链接看一看,然后第一个是你的答案:我为那个控制器创建了一个新视图,但是我有一些空值的问题,等等,我会给你新问题的链接看一看