簡體   English   中英

將Html作為參數從javascript發送到asp.net mvc控制器

[英]Send Html as parameter from javascript to asp.net mvc controller

我需要將一些HTML標記傳遞給控制器​​(請參閱我的detalle變量),使用jquery,在操作中,當我嘗試發送detalle時,我有問題,它說沒有找到,有人可以幫助我嗎?

           $('#BtnPrint').click(function() {

                var detalle = "<br><br>";

                detalle += " Yo: <b>" + '@Model.DoctorText' + "</b>";
                if ('@Model.Exequartur' != "") {
                    detalle += ", exequatur: <b>" + '@Model.Exequartur' + "</b>    <br>";
                }

                detalle += "   certifico haber examinado a: <b>" + '@Model.PatientName' + "</b> <br>";
                @*if (@Model.ide != "")
                {
                    detalle += " cedula: <b>" + txtcedula.Text + "</b>    <br>";
                }*@

                detalle += " quien presenta: <b>" + '@Model.Affections' + "</b>    <br>";
                detalle += " por lo que recomiendo: <b>" + '@Model.Recomendations' + "</b>    <br>";
                detalle += "<br> dado en: <b>" + ' @Model.Place' + "</b>, " + '@Model.MedicalCertificateDate' +
                    "    <br>";
                detalle += "<br><br><br><br>  ";
                $('#myVar').val(detalle); 



            var win = window.open(
                "@Url.Action("DetailsPrint", "Reports", new {area = "Configurations", id = @Model.Patient.Person.AuthorId, body = detalle, description = "Certificado Medico"})" )  ;

                ////  var win = window.open('http://stackoverflow.com/', '_blank');
                if (win) {
                    //Browser has allowed it to be opened
                    win.focus();
                } else {
                    //Browser has blocked it
                    alert("Porfavor, debes permitir que se abran las ventanas emergentes o el reporte no va a salir :'( ");
                }

            });

問題是你將JS變量傳遞給Url.Action在你的情況下,你應該這樣做:

$('#BtnPrint').click(function() {

    var detalle = "<br><br>";

    detalle += " Yo: <b>" + '@Model.DoctorText' + "</b>";
    if ('@Model.Exequartur' != "") {
        detalle += ", exequatur: <b>" + '@Model.Exequartur' + "</b>    <br>";
    }

    detalle += "   certifico haber examinado a: <b>" + '@Model.PatientName' + "</b> <br>";
    @*if (@Model.ide != "")
    {
        detalle += " cedula: <b>" + txtcedula.Text + "</b>    <br>";
    }*@

    detalle += " quien presenta: <b>" + '@Model.Affections' + "</b>    <br>";
    detalle += " por lo que recomiendo: <b>" + '@Model.Recomendations' + "</b>    <br>";
    detalle += "<br> dado en: <b>" + ' @Model.Place' + "</b>, " + '@Model.MedicalCertificateDate' +
        "    <br>";
    detalle += "<br><br><br><br>  ";
    $('#myVar').val(detalle); 


    var url = '@Url.Action("DetailsPrint", "Reports", new {area = "Configurations", id = @Model.Patient.Person.AuthorId, description = "Certificado Medico"})';
    url = url + "&body="+encodeURIComponent(detalle);
    var win = window.open(url);

    ////  var win = window.open('http://stackoverflow.com/', '_blank');
    if (win) {
        //Browser has allowed it to be opened
        win.focus();
    } else {
        //Browser has blocked it
        alert("Porfavor, debes permitir que se abran las ventanas emergentes o el reporte no va a salir :'( ");
    }

});

你的控制器應該是:

[ValidateInput(false)]
public ActionResult DetailsPrint(string body, int id, string description)
{
    //something
}

我建議你為每個案例使用特定的報告,你可以用dinamically的方式來做,但是,每種類型只有一個,因為所有這些都有不同的大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM