Search code examples
asp.netasp.net-mvcviewaspxgridview

How to pass parameters of the controller to the .aspx view?


i have a view in .aspx

the SIGAMVC.Models.Detalle is generated by the framework, I should never touch it

a solution that I found and it does not work here

VIEW

<%@ 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);
    } 

Solution

  • Take a look at using ViewData and ViewBag.

    ViewBag.detalle = detalle;
    

    Alternatively:

    ViewData["detalle"] = detalle;
    

    For more information on when to use which one this blog post is a great reference.