ActionButton instead of ActionLink

2019-03-17 11:13发布

I want to create a button which when clicked calls an action. I have used Html.ActionLink to create a link which does exactly that but there is no Html.ActionButton. Is there some other way?

12条回答
叛逆
2楼-- · 2019-03-17 11:29

I know this is an old topic, but this helped me:

@Html.ActionLink("New member", "Create", null, new {@class = "btn btn-default"}) 
查看更多
我只想做你的唯一
3楼-- · 2019-03-17 11:33
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" })
查看更多
小情绪 Triste *
4楼-- · 2019-03-17 11:33
@using (Html.BeginForm("ActionName", "ControllerName")){
   <input type="button" value="Submit" />
}
查看更多
ら.Afraid
5楼-- · 2019-03-17 11:35

Use this:

@using (Html.BeginForm("yourAction", "yourController"))
{
    <input type="submit" value="Some text"/>
}
查看更多
闹够了就滚
6楼-- · 2019-03-17 11:38

This seems very simple - am I missing something?

@Html.ActionLink("About", "About","Home", new { @class = "btn btn-success" })
查看更多
虎瘦雄心在
7楼-- · 2019-03-17 11:39

Is there some other way?

You could use a html <form>:

@using (Html.BeginForm("someAction", "someController"))
{
    <button type="submit">OK</button>
}
查看更多
登录 后发表回答