我想創建一個按鈕,點擊時調用一個動作。我用Html.ActionLink
來創建一個鏈接,但是沒有Html.ActionButton
。有沒有其他的方法?ActionButton而不是ActionLink
23
A
回答
18
有一些其他的方式?
你可以使用HTML <form>
:
@using (Html.BeginForm("someAction", "someController"))
{
<button type="submit">OK</button>
}
2
6
使用此:
@using (Html.BeginForm("yourAction", "yourController"))
{
<input type="submit" value="Some text"/>
}
4
@using (Html.BeginForm("ActionName", "ControllerName")){
<input type="button" value="Submit" />
}
5
a[type="button"] {
background-color: #d3dce0;
border: 1px solid #787878;
cursor: pointer;
font-size: 1.2em;
font-weight: 600;
padding: 7px;
margin-right: 8px;
width: auto;
text-decoration: none;
}
@Html.ActionLink("ActionName", "ControllerName",null, new {type = "button" })
23
下面是使用自舉的CSS按鈕,將它壓連桿,使它看起來完全一樣的按鈕的例子。
@Html.ActionLink("Select", "Select", new { id = patient.Id }, new { @class = "btn btn-primary", @style = "color:white" })
2
你可以寫一個鏈接到控制器和視圖這樣/跳過整個剃刀符號(我最近在我的本地工作!):
<a href="../Home(controller)/Index(view)"><button type="submit">OK</button></a>
+1
如果你改變你的路由配置,這會中斷。 @ Html.ActionLink方法是動態的,並且將在不依賴於某個路由配置的情況下工作。 – Alexander
15
這似乎很簡單 - 我錯過什麼?
@Html.ActionLink("About", "About","Home", new { @class = "btn btn-success" })
+3
要指出顯而易見的,這依賴於具有btn/btn-success css類(假設這是Bootstrap或類似的)。 ActionLink創建,但問題在於尋找實際的
2
使用FORMACTION
<input type="submit" value="Delete" id="delete" formaction="@Url.Action("Delete", new { id = Model.Id })" />
2
有時按鈕可能會具有嵌套的標記(如圖標)
這可能是有益的一些人:
<button type="button" onclick="location.href='@Url.Action("Action", "Controller")'" class="btn btn-success">My button name <i class="glyphicon glyphicon-search"></i></button>
類型=按鈕是必需的,以防止頁面提交...另一種可能的解決方案(如果你認爲type = button的樣子因爲該元素已經是一個按鈕)會在OnClick JavaScript處理程序中調用event.preventDefault()。
<button onclick="event.preventDefault(); location.href='@Url.Action("Action", "Controller")'" class="btn btn-success">My button name <i class="glyphicon glyphicon-search"></i></button>
1
我知道這是一個老話題,但幫我:
@Html.ActionLink("New member", "Create", null, new {@class = "btn btn-default"})
相關問題
- 1. 帶參數後的ActionLink?而不是/
- 2. 爲什麼我使用不同的actionLink後,我的Shiny(R)actionButton沒有響應?
- 3. shiny - actionButton#1完全相同actionButton#2 doesnt
- 4. MVC路線ActionLink的網址使用名稱,而不是ID
- 5. ajax actionlink重定向而不是更新標記
- 6. ActionLink在URL中顯示參數而不是查詢字符串?
- 7. ASP.NET MVC 3:如何強制ActionLink執行HttpPost而不是HttpGet?
- 8. RStudio Shiny actionButton ignored
- 9. ActionLink的不是工作,但RouteUrl確實
- 10. ActionLink的不是呼叫控制器
- 11. `actionButton` action in Shiny R
- 12. 使用actionButton在RShiny
- 13. Html ActionLink不顯示
- 14. ActionLink不起作用
- 15. 不能在ActionLink的
- 16. 禁用Firefox插件ActionButton不會變灰
- 17. CoordinatorLayout AppBarLayout和浮動actionButton不工作
- 18. 動畫ActionButton不火單擊事件
- 19. MVC - ActionLink尋找一個視圖,而不是調用控制器方法
- 20. 自定義Yii2網格ActionButton
- 21. Primefaces actionbutton多次調用
- 22. 更改顏色actionButton Shiny R
- 23. MVC ActionLink不返回PartialView
- 24. 淨MVC ActionLink的工作不
- 25. 爲什麼ActionLink URLEncode不?
- 26. MVC3 HTML ActionLink的工作不
- 27. ActionLink的表現不同
- 28. ActionLink行爲不一致
- 29. MVC ActionLink的GET工作不
- 30. ActionLink的
(只是吹毛求疵)還加上'角色=「按鈕」'的屬性是100%的自舉請求數兼容 – Alex