building relative URLs for an MVC app with JavaScript

后端 未结 3 2011
不思量自难忘°
不思量自难忘° 2020-12-17 20:24

I\'m having trouble getting C# and JavaScript/jQuery to play nice here.

I have a knockout view model, plain old javascript object... one of its property/methods fire

3条回答
  •  一向
    一向 (楼主)
    2020-12-17 21:07

    Darin's answer is the most solid, but it requires sending data using query string params on the ajax call.

    To avoid that, I simply wrapped the @Url.Action() method in quotes and appended the javascript values as I intended.

    url: "@Url.Action("Vendors", "Home")/" + viewModel.count() + "/" + viewModel.filterText(),
    

    Ultimately this produced the best results as it lets me keep a very clean url... Request.ApplicationPath seemed too hackish and can technically be null... @Url.Content() is intended for static "content" paths (ex. images, scripts)... etc.

提交回复
热议问题