asp.net mvc 3 - Razor mvc3 + jquery + UrlAction + PartialViews -


i have question jquery + razor.. want build javascript variable using razor @url.action , html attributes values of inputs. this:

var d1 = $('#d1').val();
var d2 = $('#d2').val();
var url = "@url.action("links", "partialaccount", new { begindate = "d1", enddate = "d2" })"
$("#links").fadeout("slow").load(url).fadein("slow");

how can this?

is same below?
var url = "/partialaccount/links/?begindate=" + d1 + "&enddate=" + d2;

you should use load method proposed infernalbadger:

load('@url.action("links", "partialaccount")', { begindate: d1, enddate: d2}) 

because encode parameters in d1 , d2 correctly. if can pass parameters part of querystring, not when should part of url itself.

so can use if want url be:

 /bar/foo?begindate=1-1-2001&enddate=2-2-2001 

(note /'s in date encoded)

you cannot use if want url be:

/bar/foo/1-1-2001/2-2-2001 

the @url method, begindate , enddata parameters, not work, because executed on server, before page send browser.

and method using + operator fails user enters "special characters" in input boxes (like dashes /).


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -