Reputation: 392
I'm trying to pass Username and Password using @Url.Action method but it's only passing one parameter and the second one is null. I've tried all alternatives with no success. I've also tried to pass an object of the class type with no success. This is a short sample code:
string User = ViewBag.Username;
string Pass = ViewBag.Pass;
case "CHANGE_NEXT_LOGON":
<script type="text/javascript">
BootstrapDialog.show({
title: 'Change Password',
message: $('<div></div>').load('@Url.Action("PasswordChange", "UserPassword", new { Username = User, Password = Pass})'),
type: BootstrapDialog.TYPE_PRIMARY
});
</script>
break;
I'm using a boostrap dialog plugin to generate modal popups for validation. But unlike the RedirectToAction
Method, the @Url.Action
method doesn't seem to work the same way. Can someone give me a hand?
thanks!
Upvotes: 2
Views: 3443
Reputation: 19
In my case, i could pass up to 5 parameters to Controllers via post/get methods with input, button, or a elements using razor syntax (.cshtml) in View. But for unknown reason, since yesterday, although i used the same syntax, i failed to pass the third parameter of an input element. Its third parameter value was changed to "formaction" automatically.
Upvotes: 0
Reputation: 392
I found the solution for this. The problem is that since you are passing @Url.Action within the Jquery.Load() method it is having a problem with the returned url. The @Url.Action return the & encoded in the url so to resolve this you must encapsulate the whole method in @Html.Raw(@Url.Action) and it will work.
Upvotes: 4
Reputation: 53958
This
'@Url.Action("PasswordChange", "UserPassword", new { Username, User, Password = Pass})'
should be like this
'@Url.Action("PasswordChange", "UserPassword", new { Username = User, Password = Pass})'
You have a mistype in the object initializer.
Upvotes: 2