开发者

Custom html attributesi in Html.BeginForm

开发者 https://www.devze.com 2023-03-11 03:25 出处:网络
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

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

精彩评论

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

关注公众号