Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cshtml c#出于某种原因没有监听分配的id?_C#_Jquery_Asp.net Mvc 3_Visual Studio_Razor - Fatal编程技术网

cshtml c#出于某种原因没有监听分配的id?

cshtml c#出于某种原因没有监听分配的id?,c#,jquery,asp.net-mvc-3,visual-studio,razor,C#,Jquery,Asp.net Mvc 3,Visual Studio,Razor,因此,我有一个基本的CRUD,我正在处理它,我正在尝试让Jquery验证处理它。除了需要给我的表单提供一个id之外,我几乎都已经设置好了。我正在visual studio中使用cshtml,并尝试使用以下代码将id分配给表单: @using (Html.BeginForm( new { id = "daftform" })) { @Html.ValidationSummary(true) <fieldset> <legend>News</legend> @

因此,我有一个基本的CRUD,我正在处理它,我正在尝试让Jquery验证处理它。除了需要给我的表单提供一个id之外,我几乎都已经设置好了。我正在visual studio中使用cshtml,并尝试使用以下代码将id分配给表单:

@using (Html.BeginForm( new { id = "daftform" })) {
@Html.ValidationSummary(true)
<fieldset>
<legend>News</legend> 
@使用(Html.BeginForm(new{id=“daftform”})){
@Html.ValidationSummary(true)
新闻
但是,生成的html如下所示:

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

新闻
我很确定这就是如何为元素分配id的方法,因为我使用这个方法以类似的方式分配类。有人能告诉我哪里出了问题吗

我只想让它将'daftform'指定为id,而不是操作

很抱歉,如果这是一个简单的答案,对c#来说是相当陌生的。

使用重载

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”
使用重载

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
}
这将使用(Html.BeginForm(,“actionname”,“controllername”,formmethod.post/get,new{Id=“yourId”})创建一个
form
标记,并将
Id
属性设置为
“daftform”

是使用(Html.BeginForm(,“actionname”,“controllername”,formmethod.post/get,new{id=“yourId”})的方法

这条路怎么走