2012-11-14 46 views
1

我有我的url.action和我的javascript onClick事件調用的問題。我所試圖做的就是通過我的控制器和ActionResult的方法,爲我的javascript中的參數,但我不斷收到一個錯誤信息:mvc3 razor - url.action JavaScript錯誤onClick事件

微軟JScript運行時錯誤:語法錯誤,無法識別的表達式:/的UserManager/filterGrid

此代碼:

<div class="webgrid-filter"> 

    <input name="User logged in" type="checkbox" onclick="filterGrid('@Url.Action("filterGrid", "UserManager")')" id="chkboxGridFilter" /> 

</div> 

視圖

@model IEnumerable<UserManager.Models.vw_UserManager_Model> 


@*@model UserManager.Models.vw_UserManager_Model 
*@ 
@{ 
    ViewBag.Title = "User Manager Dashboard"; 
} 

    @Html.ActionLink("Create New User", "CreateUser") 


<div class="webgrid-filter"> 

    <input name="User logged in" type="checkbox" onclick="filterGrid('@Url.Action("filterGrid", "UserManager")')" id="chkboxGridFilter" /> 

</div> 


<div class="webgrid-wrapper"> 



@{ 
    ViewBag.Title = "Jobs"; 
    WebGrid grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 15, selectionFieldName: "selectedRow", fieldNamePrefix: "gridItem"); 

} 

    @grid.GetHtml(
    fillEmptyRows: true, 
     tableStyle: "webgrid", 
       alternatingRowStyle: "webgrid-alternating-row", 
       headerStyle: "webgrid-header", 
       footerStyle: "webgrid-footer", 
       selectedRowStyle: "webgrid-selected-row", 
      rowStyle: "webgrid-row-style", 
     mode: WebGridPagerModes.All, 
columns: new[] { 
    grid.Column("UserName"), 
    grid.Column("salutation"), 
    grid.Column("FirstName"), 
    grid.Column("LastName"), 
    grid.Column("Password"), 
    //grid.Column("isactive"), 
    //grid.Column(header: "Is logged in?", format: (model) => @Html.Raw("<input type='checkbox' checked='" + ((model.isactive) ? "checked" : "unchecked") + "' />")), 
    grid.Column(header: "User logged in", format: @<text><input name="User logged in" 
     type="checkbox" @(item.isactive == true ? "Checked" : null) onclick="logUserOff('@Url.Action("LogUserOff", "UserManager", new {userid = item.userid})')" id="chkboxIsActive" /></text>), 
    grid.Column("isApproved"), 
    grid.Column("MaxConcurrentUsers"), 
    grid.Column("email"), 
    grid.Column("group_name"), 
    grid.Column("module_name"), 


    grid.Column(header:"Edit", format:@<text><div id="btnEditSelectedRow"> 
     "@Html.ActionLink("Edit record", "EditUser", "UserManager", new { 
     userid = item.userid, 
     salutation = item.salutation, 
     firstname = item.FirstName, 
     lastname = item.LastName, 
     password = item.Password, 
     isactive = item.isactive, 
     isapproved = item.IsApproved, 
     maxconcurrentusers = item.MaxConcurrentUsers, 
     email = item.email, 
     module = item.module_name, 
     group = item.group_name }, null)</div></text>), 

    grid.Column(header:"Delete", format:@<text><div id="btnDelSelectedRow"> 
     "@Html.ActionLink("Delete record", "DeleteUser", "UserManager", new { 
     userid = item.userid, 
     username = item.UserName, 
     salutation = item.salutation, 
     firstname = item.FirstName, 
     lastname = item.LastName, 
     password = item.Password, 
     isactive = item.isactive, 
     email = item.email, 
     module = item.module_name, 
     group = item.group_name }, null)</div></text>) 


}) 
</div><br /> 

<script type="text/javascript"> 
    $(document).ready(function() { 

     // Disable checkboxs where a user is not active. 
     $(".webgrid-wrapper input:not(:checked)").attr("disabled", "disabled"); 

     // Style tables. 
     function jQueryUIStyling() { 
      $('input:button, input:submit').button(); 

      $('.webgrid-wrapper').addClass('ui-grid ui-widget ui-widget-content ui-corner-all'); 
      $('.webgrid-title').addClass('ui-grid-header ui-widget-header ui-corner-top'); 
      jQueryTableStyling(); 
     } // end of jQueryUIStyling 

     function jQueryTableStyling() { 
      $('.webgrid').addClass('ui-grid-content ui-widget-content'); 
      $('.webgrid-header').addClass('ui-state-default'); 
      $('.webgrid-footer').addClass('ui-grid-footer ui-widget-header ui-corner-bottom ui-helper-clearfix'); 
     } // end of jQueryTableStyling 
    }); 
</script> 
<script type="text/javascript"> 
    function logUserOff(url) { 
     var answer = confirm('Are you sure you want to save this data?') 
     if (answer) { 
//   alert(url + ": " + value); 

      $.ajax({ 
       url: url, 
       type: "POST" 
//    data: value 
      }).done(function() { 
       $(this).addClass("done"); 
      }); 


      return true; 
     } 
     else { 
      return false; 
     } 
    }; 
</script> 

<script type="text/javascript"> 

    function filterGrid(url) { 
     alert($(url).val()); 
    } 

</script> 

這是的javascrip T:

throw"Syntax error, unrecognized expression: "+a 

任何人都知道我做錯了:

<script type="text/javascript"> 

    function filterGrid(url) { 
     alert($(url).val()); 
    } 

</script> 

錯誤從jQuery的1.5.1起源?謝謝!

+0

檢查頁面的源代碼,並粘貼到這裏正在打印的內容。 – Diego

+0

該錯誤來自我的jquery腳本以及更奇怪的,因爲我在webgrid中的其他地方使用url.helper,它的工作原理。 –

+0

@Diego出於某種原因,我的jQuery腳本中出現錯誤。 –

回答

0

此錯誤ID導致您在警報中顯示URL的值。

你應該寫這樣的

function filterGrid(url) { 
    alert(url); 
}