c#
  • asp.net
  • asp.net-mvc
  • razor
  • 2017-07-31 164 views 2 likes 
    2

    我正在用C#和.NET Framework 4.7开发ASP.NET MVC 5应用程序。将Model属性作为参数传递给Url.Action

    我遇到了麻烦,试图通过Url.Action传递参数。当我使用这个:

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

    我得到这个:

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

    我也曾尝试:

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

    这带来的另一个结果是:

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

    与错误:

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

    我该怎么办?

    顺便说一下,我使用剃刀。

    +0

    您使用的ASPX视图或Razor视图引擎? –

    +0

    您不能像aspx代码那样使用剃须刀 - 使用@ @ Url.Action(“Index”,“ProductionOrder”,新{isWizard = @ Model.IsWizard}) –

    +0

    只需删除<%: and %> – daniell89

    回答

    3

    标记和@Resources指出您正在使用Razor视图引擎的事实。然而,你的网址是使用aspx的。不应该混合使用这两种,所以如果你使用Razor,坚持Razor - aspx标记根本不会被识别。因此:

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

    完美答案! –

    0

    试试这个

    <input type="button" value="@Resources.ProductCreateOmitCaption" 
        onclick='location.href = @Url.Action("Index","ProductionOrder")' 
         + '?isWizard='[email protected] +'/>' 
    
    +0

    OP正在使用剃须刀视图。 –

    +0

    @PowerStar不知道 –

    +0

    好吧:) cool !!! –

    相关问题