Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How can we set the url(Action, controller and query string) using javascript in mvc.

Please suggest.

Thank you,

Regards,
Ashish
Posted
Comments
Aashish vermaa 16-Sep-14 6:27am    
a few seconds ago|LINK

But I want to dynamical add css classes and also want to call javascript method "EditUrl();" together.

I am using the following code:

@Html.ActionLink("Single Choice", "SingleChoice", "Question", new { sectionid = "0" }, (ViewBag.Type == 1 || ViewBag.Type == 4 || ViewBag.Type == 5) ? new { @class = "ancbtnClass editUrl" } : new { @class = "ancdisableCss" })

Please advise.

Thank you,

1 solution

C#
javascript:

function OnEdit(link) {

debugger;
if (sectionId != 0 && sectionId != "a") {
link.originalHref = link.originalHref || link.href;
link.href = link.originalHref.replace("-1", sectionId);
}
else if (sectionId == "a") {
alert('Please add section first');
return false;
}
else {
alert('Please select a section to add question');
return false;
}
return true;
}

cshtml:


@if (ViewBag.Type == 1 || ViewBag.Type == 4 || ViewBag.Type == 5)
{
@Html.ActionLink("Arrange", "Arrange", "Question", new { id = 0, sectionid = "-1", assessmentId = ViewBag.AssessmentId }, new { @class = "ancbtnClass editUrl", onclick = "javascript:return OnEdit(this);" })
}
else
{
@Html.ActionLink("Arrange", "Arrange", "Question", new { @class = "ancdisableCss" })
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900