Click here to Skip to main content
14,212,087 members
Rate this:
Please Sign up or sign in to vote.
In my controller I have this function:
Function AppError() As ActionResult
          Dim myScript As Object = "popup(" + Properties.postError + ")"
          Return RedirectToAction("main", myScript)
      End Function

With this function I want to call my razor page where I have a Javascript named `popup` whith a parameter `Properties.postError`.

My script is:
<script type="text/javascript">
       var errMsg;
       function popup(msg) {
           errMsg = msg;
           window.alert(errMsg);
           window.window.focus();
           if (window.confirm)
               errmsg = '';
           msg = '';
       }
   </script>

What I need is to popup the error message.
I follow the programm throu my debugger and I saw that it goes to my page.
But no error message window raise up.
I have already search in the web for this option without any success.
Is someone to assist me on this issue?

What I have tried:

ADDITION - 16/2/19 12:50
what I have done so far is the following:

Function CBError() As ActionResult
        Dim myScript As Object = "popup(" + Properties.postError + ")"
        ViewData.Add(New KeyValuePair(Of String, Object)("ScriptName", myScript))
        Return View("main", myScript)
    End Function

As we can see I've change the function by addiding the ViewData
I Add a value pair arguments 1) the name 2) the value
The action of addition it works just fine and the dictionery receive it.
I my script (which is in my reazor page) I put the following:

<script type="text/javascript">
   var vd = @ViewData.Item(0);
       function popup(msg) {
            var errMsg;
        errMsg = msg;
        window.alert(errMsg);
        window.window.focus();
        if (window.confirm)
            errmsg = '';
        msg = '';
        //{ window.location.href = "/" }
    }
</script>

When I stop (with the bebugger) in the instruction var vd = @ViewData.Item(0); I see that the ViewData is complitely empty. No values no nothing.
I also add this window.onload = @Html.Raw(ViewBag.MyScript);
And in debugger threw me an error

"Uncaught SyntaxError: Unexpected token ;"



.
Posted
Updated 21-Feb-19 6:26am
v2
Comments
F-ES Sitecore 18-Feb-19 5:35am
   
View the source of the page in the browser and see what the javascript looks like, that might give you a clue as to why it isn't working.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You're running into VB's implicit type coercion nightmare.
  • The ViewData property is a ViewDataDictionary object[^], which is a dictionary with a string key.
  • You are adding an item with the key "ScriptName";
  • You are trying to retrieve an item with the key 0. VB "helpfully" converts that to the string "0" for you;
  • There is no item in the dictionary with the key "0".


You have to use the same key to retrieve the item that you used when you added it:
@ViewData("ScriptName")
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

The issue has solved by using ajax script...
But thanks any way...
Now I post another question on which nobody gives an answer (until now)
So lets try to solve this issue... which is very important...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.2 | Last Updated 21 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100