SoftwareSavant
SoftwareSavant

Reputation: 9737

how to get javascript variable into URL.Action mvc method

onSelectRow: function(id) {
   document.location.href = '@Url.Action("EditEncounter", "EditEncounter", new { encounterId = "'<%:id%>'", popId = TempData["POPULATIONID"] })'
                            //new { encounterId = temp.EncounterId, popId = (int)TempData["POPULATIONID"] }
}

How in sam hill do I get that id variable into my Url.Action method?

This is what I am looking at when I debugg

document.location.href = '/EditEncounter/EditEncounter?encounterId=%40id&amp;popId=2'

Upvotes: 4

Views: 3770

Answers (1)

SoftwareSavant
SoftwareSavant

Reputation: 9737

var dummyURL ='@Url.Action("EditEncounter", "EditEncounter", new { encounterId = -2, popId = TempData["POPULATIONID"] })';
                            var path =dummyURL.replace("-2", id);
                            debugger;
                            document.location.href = path;

That appears to work.

Upvotes: 4

Related Questions