开发者

Custom html attributesi in Html.BeginForm

I know that in the html helper BeginForm available in asp.net mvc there is a param called htmlAttributes. How can I use it witouth specif开发者_运维百科y the previous params? I don't want to override the default action/method values


You could do something like this:

@using(Html.BeginForm(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), FormMethod.Post, new{title = "title"}))
{ 
    ...
}

which outputs:

<form action="/" class="someclass" method="post">
</form>

It's not exaclty what you wanted and it's not pretty. You do have to specify the FormMethod.

Or add the attributes you need via jQuery.


Passing null as the value of the BeginForm function will apply the default params value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜