2017-05-04 16 views
0

按鈕控制器我有一個按鈕:如何調用從使用jQuery

<button class="btn btn-info" id="details" value="@scr.Id">Details</button> 

,我想它重定向到我的控制器

public ActionResult Details(int par) 
{ 
    var screening = _context.Screenings.Single(s => s.Id == par); 
    return View(screening); 
} 

我怎樣才能做到這一點使用jQuery?

+0

改變你的標籤MVC ..這不是ASP.NET –

+0

你不需要「jQuery的」 - 只是一個基本的錨/ HREF,您可以使用一個'@ Html'助手中的數字,產生的方式。 –

回答

1

變化你按鈕,這樣的事情

@Html.ActionLink("Details", "Details", "Your Controller Name", new {@class = "btn btn-info"}) 

,它應該很好地工作不需要JQuery的

,如果你需要的jQuery

使用Ajax調用

$("#details").click(function() { 
$.ajax({url: "/ControllerName/Details/YourIDValue", success: function(result){ 

    }}); 
}) 
0

如果你想用JQuery發送按鈕的ID,你可以試試這個

$(document).ready(function() { 
     $("#details").on('click', function (e) { 
       e.preventDefault(); 
       window.location.href = '@Url.Action("Details", "ControllerName")?par=' + $(this).val(); 

      } 
     ); 
    });