Pass a Model property as a parameter to an Url.Action

Van*_*nel 5 c# asp.net asp.net-mvc razor

I'm developing an ASP.NET MVC 5 app with C# and .NET Framework 4.7.

I'm having troubles trying to pass parameters with Url.Action. When I use this:

<input type="button" value="@Resources.ProductCreateOmitCaption" 
    onclick='location.href=<%: Url.Action("Index", "ProductionOrder", new { isWizard = @Model.IsWizard}) %>' />
Run Code Online (Sandbox Code Playgroud)

I get this:

<input type="button" value="Continue" 
    onclick='location.href=<%: Url.Action("Index", "ProductionOrder", new { isWizard =}) %>' />
Run Code Online (Sandbox Code Playgroud)

I have also tried:

<input type="button" value="@Resources.ProductCreateOmitCaption" 
    onclick="location.href='<%: Url.Action("Index", "ProductionOrder", new { isWizard = @Model.IsWizard}) %>'" />
Run Code Online (Sandbox Code Playgroud)

With this another result:

<input type="button" value="Continue" 
    onclick="location.href='<%: Url.Action("Index", "ProductionOrder", new { isWizard = False}) %>'" />
Run Code Online (Sandbox Code Playgroud)

With the error:

JavaScript critical error at line 177, column 60 in http://AnotherPC:53827/Products/Create\n\nSCRIPT1015: Unfinished string constant

How can I do it?

By the way I'm using Razor.

And*_*rei 4

标签 和@Resources指出您正在使用 Razor 视图引擎。然而,对于您的 URL,您正在使用 aspx 之一。两者不应该混合,因此如果您使用 Razor,请坚持使用 Razor - aspx 标记根本不会被识别。因此:

<input type="button" value="@Resources.ProductCreateOmitCaption" 
    onclick="location.href='@Url.Action("Index", "ProductionOrder", new { isWizard = Model.IsWizard})'" />
Run Code Online (Sandbox Code Playgroud)