0

I'm trying to use the HTTP context razor method to map a server path within a javascript code block. However it's causing an exception with "illegal characters". I'm not sure which characters to encase it in, so razor see's it as c#.

    $(document).ready(function () {
    $('#StudentTableContainer').jtable({
        title: 'Asset Classes',
        paging: true,
        sorting: true,
        pageSize: 25,
        defaultSorting: 'Name ASC',
        actions: {
            listAction: '@(HttpContext.Current.Server.MapPath("GetAssetData?prod=funds"))'
        }
      });
    });
0

1 Answer 1

2

There is no problem with razor syntax in Javascript ,you are sending querystring in server.mappath which is wrong :-

it should be like this :

 actions: {
            listAction: '@(HttpContext.Current.Server.MapPath("~/GetAssetData"))'
        }

instead of

actions: {
            listAction: '@(HttpContext.Current.Server.MapPath("~/GetAssetData?prod=funds"))'
        }

That is why "illegal characters" error is coming.

As far as i m understanding your question,i think you want to give path of a action in listAction then do it as :

actions: {
            listAction: '@(Url.Action("action name","controller name",new { prod="funds" }))'
        }
Sign up to request clarification or add additional context in comments.

Comments

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.