问题描述
我实现ASP.NET MVC的方式不是跨ASP.NET Web窗体,因此很难理解如何更好地将值从ASP.NET MVC控制器传递到MVC视图中的ASP.NET Webforms脚本./p>
例如,控制器动作:
public ViewResult Print(string id)
{
...
string myvar = "realvalue";
return 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>
如何将控制器操作中的myvar
值分配给View中的par1
变量而不是"stubvalue"?
将setter调用移至onload事件
受保护的覆盖无效void OnLoad(EventArgs e) { base.OnLoad(e); 字符串par1 =(字符串)ViewData ["myvar"]; ReportViewer1.Report =新的MyProj.Web.Reports.Rep1(par1); }
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); }
这篇关于如何将值从ASP.NET MVC控制器传递到MVC视图中的ASP.NET Webforms控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!