My way to ASP.NET MVC was not across ASP.NET Web Forms, so it's hard for me to understand how better to pass value from ASP.NET MVC controller to ASP.NET webforms script which is inside MVC View.
For example, controller action:
public ViewResult Print(string id)
{
...
string myvar = "realvalue";
return View();
}
My view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
...
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script runat="server">
...
string par1 = "stubvalue";
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ReportViewer1.Report = new MyProj.Web.Reports.Rep1(par1);
}
</script>
<telerik:ReportViewer runat="server" ID="ReportViewer1" />
</asp:Content>
How to assign a value of myvar
from a controller action to par1
variable in the View instead "stubvalue"?
Move the setter call to onload event
protected override void OnLoad(EventArgs e) { base.OnLoad(e); string par1 = (string) ViewData["myvar"]; ReportViewer1.Report = new MyProj.Web.Reports.Rep1(par1); }