Window and partial view

3 posts, 0 answers
  1. Adem
    Adem avatar
    13 posts
    Member since:
    Feb 2016

    Posted 20 Feb Link to this post

    I want to use window with partial view.

    There are two function in partial view. When window was opening I got error : "Uncaught SyntaxError: Unexpected token :"

    If I remove second parameter(prm2) in second function(getCustomer2) then it works fine.(MyWindowPartial.cshtml line 14)

    What can I do?

     

    <script>
    function getCustomer1()    {
         return {  wfTypeId : @(Html.Raw(Json.Encode(ViewBag.WfTypeId))), 
                    folderIdList : @(Html.Raw(Json.Encode(ViewBag.WfTypeId)))        };   }
    function getCustomer2()   {
        return  { wfTypeId : @(Html.Raw(Json.Encode(ViewBag.WfTypeId))),
                      prm2 : "deneme"       };
    }
     </script>
  2. Adem
    Adem avatar
    13 posts
    Member since:
    Feb 2016

    Posted 20 Feb in reply to Adem Link to this post

    if I surround with @section Scripts { <script>...</script> }  ıt worked fine. 

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 22 Feb Link to this post

    Hello,

    The problem appears to stem from the formatting of the JavaScript code. It is not visible in the code snippet, posted her, however you will notice it in the sample you attached.

    There is a line break between the return statement and the object that should be returned by the getCustomer2 method. You need to create the object on the same line so it can be returned by the method:
    function getCustomer1()
    {
        return {
            wfTypeId: @(Html.Raw(Json.Encode(ViewBag.WfTypeId))),
            folderIdList: @(Html.Raw(Json.Encode(ViewBag.WfTypeId)))
        };
    }
    function getCustomer2()
    {
        return {
            wfTypeId: @(Html.Raw(Json.Encode(ViewBag.WfTypeId))),
            prm2: "deneme"
        };
    }


    Regards,
    Slav
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top