如何将控制器的参数传递给.aspx视图?

时间:2018-05-07 13:22:26

标签: asp.net asp.net-mvc view aspxgridview

我在 .aspx

中有一个视图

SIGAMVC.Models.Detalle    由框架生成,我永远不应该触摸它

我找到的解决方案,但它不起作用here

查看

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SIGAMVC.Models.Detalle>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

             <h4><b><%:Session["TEST"] %></b></h4>     <%-- i tried por session but not found --%>   
   <h1><%=MyValue%></h1>  <%-- too --%>  
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MenuContent" runat="server">
</asp:Content>

CONTROLLER

  protected string MyValue { get; set; }
    [HttpPost]
    public ActionResult Create(Detalle detalle, int id)
    {
       Session["TEST"] = "RODRIGO ALEX";   //first tried
      this.MyValue = "Some Value";      // second tried
       return View(detalle);
    } 

1 个答案:

答案 0 :(得分:1)

看一下使用ViewData和ViewBag。

ViewBag.detalle = detalle;

可替换地:

ViewData["detalle"] = detalle;

有关何时使用此博客post is a great reference

的更多信息