0

So I have a basic CRUD I am working on, and Im trying to get Jquery validation working on it. I have it almost all set up except I need to give my form an id. I am using cshtml in visual studio and try to assign the id to the form using the following code:

@using (Html.BeginForm( new { id = "daftform" })) {
@Html.ValidationSummary(true)
<fieldset>
<legend>News</legend> 

However the generated html looks like this:

<form action="/News/Create/daftform" method="post">    <fieldset>
    <legend>News</legend>

I am pretty sure this is how to assign an id to an element as I use this method to assign classes in a similar way. Can anyone tell me where im going wrong?

I just want it to assign 'daftform' as an id not as an action.

Sorry if its a simple answer, fairly new to c#.

4

2 に答える 2

3

この オーバーロードを使用

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    FormMethod method,
    Object htmlAttributes
)

したがって、コードを次のように変更できます

@using (Html.BeginForm("Create","News",FormMethod.Post, new { id = "daftform" }))
{
  //form elements
}

これにより、プロパティがに設定されたformタグが作成されますId"daftform"

于 2012-08-23T13:43:50.180 に答える
0

@using (Html.BeginForm(,"actionname","controllername",formmethod.post/get, new {id = "yourId"})

行く方法です

于 2012-08-23T13:51:02.727 に答える