Send html as parameter from javascript to asp.net mvc controller

I need to pass some HTML markup to the controller (see my detalle variable ) using jquery, in action this is a problem, when I try to send detalle , it said not found, can anyone help me?

           $('#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 :'( ");
                }

            });

      

+3


source to share


2 answers


I recommend that you use a specific report for each case, you can do it dynamically, but only one for each type, because they are all different sizes



+1


source


The problem is that you are passing the JS variable to Url.Action In your case, you should do the following:

$('#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 :'( ");
    }

});

      



And your controller should be:

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

      

+1


source







All Articles