本文介绍了如何将值从ASP.NET MVC控制器传递到MVC视图中的ASP.NET Webforms控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我实现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控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:07