将Webform控件转换为Razor语法 [英] Convert webform control to Razor syntax

查看:372
本文介绍了将Webform控件转换为Razor语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获得了此控件,并且工作正常,但是我需要在我的mvc3项目中使用它.我尝试了一下,但是没有工作.我希望有一个人可以帮助我.多数民众赞成在Webform自定义控件代码:

i got this control and it works fine, but i need to use it on my mvc3 project. I tryed my way but didnt work. I hope someone can help me. Thats the webform custom control code:

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BoletoCS.aspx.cs" Inherits="BoletoCS" %>
<%@ Register Assembly="Impactro.Cobranca" Namespace="Impactro.WebControls" TagPrefix="cob" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Boleto</title>
    <style type="text/css">
    .BolCell { font-size: 7pt; font-family: Verdana; }
        .BolField { font-weight: bold; font-size: 12px; font-family: arial; }
</style>
</head>
<body>
    <form id="form1" runat="server">
         <cob:BoletoWeb id="bltPag" runat="server" CssCell="BolCell" CssField="BolField" ></cob:BoletoWeb>
     </form>
</body>
</html>

CodeBehind:

CodeBehind:

using System;
using Impactro.Cobranca;

public partial class BoletoCS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var cedente = new CedenteInfo
        {
            Cedente = "CURRICULO AUT ASS E CONS EM RH",
            Banco = "341",
            Agencia = "6157",
            Conta = "30901-1",
            Carteira = "175",
            CNPJ = "14.765.492/0001-10"
        };

        var sacado = new SacadoInfo { Sacado = "RODRIGO MANGUINHO" };

        var boleto = new BoletoInfo
        {
            NossoNumero = "44",
            ValorDocumento = 99,
            DataDocumento = DateTime.Now,
            DataVencimento = DateTime.Now.AddMonths(1),
            LocalPagamento = "PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.",
            Especie = Especies.RC,
            Instrucoes = "NÃO ACEITAR PAGAMENTO APÓS O VENCIMENTO."
        };

        bltPag.MakeBoleto(cedente, sacado, boleto);
    }
}

此自定义控件继承自webcontrol.它基本上是渲染一张桌子. 我尝试用Razor做到这一点,但没有奏效.也没有任何错误.

This custom control inherits from webcontrol. It basically render a table. I tryed do this with Razor but didnt work. Didnt have any errors also.

@using Impactro.WebControls
@using Impactro.Cobranca

@{
    var ci = new CedenteInfo
    {
        Cedente = "CURRICULO AUT ASS E CONS EM RH",
        Banco = "341",
        Agencia = "6157",
        Conta = "30901-1",
        Carteira = "175",
        CNPJ = "14.765.492/0001-10"
    };

    var si = new SacadoInfo { Sacado = "RODRIGO MANGUINHO" };

    var bi = new BoletoInfo
    {
        NossoNumero = "44",
        ValorDocumento = 99,
        DataDocumento = DateTime.Now,
        DataVencimento = DateTime.Now.AddMonths(1),
        LocalPagamento = "PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.",
        Especie = Especies.RC,
        Instrucoes = "NÃO ACEITAR PAGAMENTO APÓS O VENCIMENTO."
    };

    var bw = new BoletoWeb
    {
        CssCell = "",
        CssField = "",
        ImagePath = Url.Content("~/images/bank-ticket")
    };

    bw.MakeBoleto(ci, si, bi);
}

推荐答案

您不能在ASP.NET MVC应用程序中使用服务器端控件.尽管使用Razor的WebForms视图引擎仍然可以(但不建议这样做),但这不再可行.如果绝对需要调用服务器端控件,请尝试针对需要在其中调用控件的特定视图使用WebForms视图引擎.但是,如果此控件依赖于ViewState和PostBacks,它将无法正常工作.

You cannot use server side controls in an ASP.NET MVC application. While this was still possible (but not recommended) with the WebForms view engine with Razor this is no longer possible. If you absolutely need to call server side controls try using the WebForms view engine for the particular view in which you need to call the control. But if this control relies on ViewState and PostBacks it won't work.

这篇关于将Webform控件转换为Razor语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆