3

I need to pass some HTML markup to the controller (please see my detalle variable), using jquery, in the action is that I have the problem when I try to send the detalle, it said that is not found, somebody can 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 :'( ");
                }

            });

2 Answers 2

1

I recomend you to use specific report for each case, you can do it dinamically, but, just one for each type of it, because all of them, have diferent sizes

Sign up to request clarification or add additional context in comments.

1 Comment

Definily i need to do it on this way, because it was imposible to adap it as a dinamically report for all, thanks bro and welcome to stackoverflow
1

Problem is that you passing JS variable into Url.Action In your case, you should do like that:

$('#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
}

5 Comments

When I try it, trow this error JavaScript critical error at line 402, column 43 in http://localhost:13076/Medicals/Patients/DetailsMedicalCertificates/1\n\nSCRIPT5017: Syntax error in regular expression
I've fixed my answer
thanks, it solve the problem, but, now I have another, on the view is not rendering the html, any idea of what could happend? the view is showing like this *<br><br> Yo: <b>Pepe</b>, exequatur: <b>3333</b> <br> certifico haber examinado a: <b>Lala</b> * this is my html on the view <td> <div> @ViewBag.MyBody </div> </td>
You need to use @Html.Raw(ViewBag.MyBody)
excelent man, I dont know what will happend to me if in the world doesnt exist persons like you, too many thanks :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.