1

I have been working on a MVC4 C# project and in my Razor view need to send two parameters to a specific MVC Action when the due button is clicked, I decided to use jQuery in order to send the two parameters.

This is the code in the click event:

$('#salir').click(function () {
    window.location.href = '@Url.Action(actionName: "MostarOrdenInicioEmpleados", controllerName: "Home", new { id = Convert.ToString(Model.num_doc), grupo= Convert.ToInt32(Model.grupo)})';
});

and this is the controller where I need to send the two parameters:

[HttpGet]
[Authorize]
public ActionResult MostarOrdenInicioEmpleados(string id, Int32 grupo)

But this is the error in the Razor view:

enter image description here

Error text:

Named argument specifications must appear after all fixed arguments have been specified

Could you please tell me what the problem is?

0

2 Answers 2

3

You've used two named arguments (with actionName: and controllerName: before you used a fixed (i.e. un-named, specifically positioned) argument (in this case, it's your argument starting with new, which you didn't name), whereas the error says you can only put named arguments after the fixed ones.

So either

a) change the order of the arguments so the named ones are last

b) name all the arguments, or

c) don't name any of the arguments and make sure they're in the expected order.

Sign up to request clarification or add additional context in comments.

Comments

2

This is just saying: if you provide named arguments (in your case, actionName:, controllerName:), they have to come after non-named (aka fixed arguments).

In your case, you can simply fix this by making your final argument (routeValues) also a named argument:

    window.location.href = '@Url.Action(actionName: "MostarOrdenInicioEmpleados", controllerName: "Home", routeValues: new { id = Convert.ToString(Model.num_doc), grupo= Convert.ToInt32(Model.grupo)})';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.