Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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
C# 找不到部分资源中的BeginForm_C#_Asp.net Mvc_Razor - Fatal编程技术网

C# 找不到部分资源中的BeginForm

C# 找不到部分资源中的BeginForm,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我有一个无法解决的路由问题: 部分方法: public ActionResult UserProjMetric(int id, DateTimeOffset? startDate, DateTimeOffset? endDate){ // some logic code here return PartialView("_UserProjMetric", model); } 主要观点: <div id="dailyMetric"> @{

我有一个无法解决的路由问题:

部分方法:

public ActionResult UserProjMetric(int id, DateTimeOffset? startDate, DateTimeOffset? endDate){
   // some logic code here
   return PartialView("_UserProjMetric", model);
}
主要观点:

<div id="dailyMetric">
            @{
                Html.RenderAction("UserProjMetric", "Users", new { id = Model.Id });
            }
        </div>

@{
RenderAction(“UserProjMetric”,“Users”,new{id=Model.id});
}
所有这些都非常有效。我遇到的问题是,我正在做一个HTML.BeginForm,但它不起作用。它声称找不到资源

<div class="dateContainer">
                        @using (Html.BeginForm("UserProjMetric", "Users", new { id = 23 }))
                        {
                            <span class=""><input type="text" class="startDate dates" placeholder="Start Date" id="from" name="from"></span>
                            <span class=""><input type="text" class="endDate dates" placeholder="End Date" id="to" name="to"></span>
                            <input class="btn btn-small" type="submit" value="Submit" />
                        }


                    </div>

@使用(Html.BeginForm(“UserProjMetric”,“Users”,new{id=23}))
{
}

我缺少什么?

您最好定义一个模型类,如:

public class UserProjMetricModel
{
   public int id {get; set;} 
   public DateTimeOffset? startDate {get; set;} 
   public DateTimeOffset? endDate {get; set;}
}
然后添加动作方法签名,如

public ActionResult UserProjMetric(UserProjMetricModel userProjMetric)
路由器应正确识别要路由到的正确端点

另外,不要忘记删除视图中的id路由值
new{id=23}
,而是将其作为隐藏字段插入

@using (Html.BeginForm("UserProjMetric", "Users", FormMethod.Post))
{
   <input type="hidden" name="id" value="23"/>
   <span class=""><input type="text" class="startDate dates" placeholder="Start Date" id="from" name="from"></span>
   <span class=""><input type="text" class="endDate dates" placeholder="End Date" id="to" name="to"></span>
   <input class="btn btn-small" type="submit" value="Submit" />
 }
@使用(Html.BeginForm(“UserProjMetric”,“Users”,FormMethod.Post))
{
}

我建议您从表单元素中删除id=23,并将其作为表单中的隐藏元素。我认为所有其他代码都在工作

<input type="hidden" id="id" name="id" value="23" />


UserProjMetric
不同吗?\u UserProjMetric只是部分视图,而不是控制器。需要注意的一点是,我的路由看起来很正常……localhost:1234/Users/23。我需要它路由到localhost:1234/Users/23/UserProjMetricI,它仍然声称找不到referenceDid所有这一切,但我必须删除HttpPost属性。因为对于Html.RenderAction(“UserProjMetric”,“Users”,新的UserProjMetricModel{id=Model.id??default(int)});除非[httppost]被接管,否则它显然无法工作out@allencoded,您是否将FormMethod.Post放在Html.BeginForm的视图中?无论如何,我将从控制器方法中删除HttpPost属性。