Search code examples
jqueryrazormodel-view-controllerc3

How to display the message in the popup?


i have a popup that was designed in a html page.enter image description here

i need to show the message "This batch contains " + TargetCount+ " records. Please press Continue to finish importing your data.", near the buttons outside the border,where the "TargetCount" returns from controller. I have my controller like,

   [HttpPost]
   public JsonResult UploadFile(string id)
   {
   if (this.Request.Files.Count >= 1)
        {
            var file = Request.Files[0];
   ImportFileSetting importFileData = importHandler.SaveUploadedFile(file, caseNumber, isFieldName);
        return Json(importFileData.TargetCount);
        }
        return Json(null);
    }

and i have my jquery like,

function UploadFile(event) {
sendFile(event.target.files[0]);}
function sendFile(file) {
var data = new FormData();
data.append("Uploaded", file);
var id =true;
$.ajax({
    type: 'post',
    url: '/Import/UploadFile?id=' + id,
    data: data,
    success: function (data)
    {
        if (data) {
            var errorMessageOne = " This batch contains " + data + " records.  Please press Continue to finish importing your data.";
            return errorMessageOne;
        }

    },
});}

As iam the beginner i dont how to return this message. Kindly tell me how to achieve this.


Solution

  • $.ajax({
    type: 'post',
    url: '/Import/UploadFile?id=' + id,
    data: data,
    success: function (data)
    {
        if (data) {
            var errorMessageOne = " This batch contains " + data + " records.  Please press Continue to finish importing your data.";
            <!-- example code -->
            $('.msgbox').html(errorMessageOne);
        }
    
    },
    });
    

    I've taken your ajax code and edited as above! You don't have to return the msg! just take the element you want to show the message and add the var element in it's html as I've shown in the example! Since my code is an example you would need to look a bit into jquery and select your necessary element to show the message.

    for an example if you have a h1 tag with a class message the code should look as following.

    $('.message').html(errorMessageOne);