Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.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#MVC视图模型未传递给控制器_C#_Asp.net Mvc - Fatal编程技术网

c#MVC视图模型未传递给控制器

c#MVC视图模型未传递给控制器,c#,asp.net-mvc,C#,Asp.net Mvc,我有一个模型: public class PersonViewModel { public int Id { get; set; } [MaxLength(25)] public string Firstname { get; set; } [MaxLength(50)] public string Surname { get; set; } } 以及一个ViewModel,其中包含一个实例和上述内容的列表: public class PeopleSea

我有一个模型:

public class PersonViewModel
{
    public int Id { get; set; }
    [MaxLength(25)]
    public string Firstname { get; set; }
    [MaxLength(50)]
    public string Surname { get; set; }
}
以及一个ViewModel,其中包含一个实例和上述内容的列表:

public class PeopleSearchViewModel
{
    public PersonViewModel Person { get; set; }
    public List<PersonViewModel> People { get; set; }
}
表单提交时模型未传递给控制器? 或者可能是这样,但是没有填充单个属性


ActionResult
Search
方法肯定正在被调用,只是
ModelsNTPassing
在其嵌套属性中没有值不确定为什么要同时使用HiddenFor和TextBoxFor作为FirstName。 请尝试在视图中注释/删除
@Html.HiddenFor(m=>m.Person.Firstname)
语句

@model PeopleSearchViewModel

@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
    @Html.LabelFor(m => m.Person.Firstname)
    @*@Html.HiddenFor(m => m.Person.Firstname)*@
    @Html.TextBoxFor(m => m.Person.Firstname)
    @Html.ValidationMessageFor(m => m.Person.Firstname)

    <input type="submit" value="Search" id="Whatever"/>
}
@model PeopleSearchViewModel
@使用(Html.BeginForm(“搜索”、“主页”、FormMethod.Post))
{
@LabelFor(m=>m.Person.Firstname)
@*@Html.HiddenFor(m=>m.Person.Firstname)*@
@Html.TextBoxFor(m=>m.Person.Firstname)
@Html.ValidationMessageFor(m=>m.Person.Firstname)
}

不确定为什么您的FirstName同时具有HiddenFor和TextBoxFor。 请尝试在视图中注释/删除
@Html.HiddenFor(m=>m.Person.Firstname)
语句

@model PeopleSearchViewModel

@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
    @Html.LabelFor(m => m.Person.Firstname)
    @*@Html.HiddenFor(m => m.Person.Firstname)*@
    @Html.TextBoxFor(m => m.Person.Firstname)
    @Html.ValidationMessageFor(m => m.Person.Firstname)

    <input type="submit" value="Search" id="Whatever"/>
}
@model PeopleSearchViewModel
@使用(Html.BeginForm(“搜索”、“主页”、FormMethod.Post))
{
@LabelFor(m=>m.Person.Firstname)
@*@Html.HiddenFor(m=>m.Person.Firstname)*@
@Html.TextBoxFor(m=>m.Person.Firstname)
@Html.ValidationMessageFor(m=>m.Person.Firstname)
}

PatientSearchPageViewModel是要接收的正确型号吗?我们能看看它的定义吗?对不起,那是个打字错误。它应该与类和视图中定义的
PeopleSearchViewModel
相同。ActionResult函数必须与
Html.BeginForm
中的第一个参数匹配。请看这里的一个例子:不,对不起,这也是以前版本的一个拼写错误,现在更正了。在我的控制器上调用了正确的操作,但是模型没有通过。在Request.Forms对象中,参数作为key/val对存在
Person.FirstName
要接收的模型是否正确?我们能看看它的定义吗?对不起,那是个打字错误。它应该与类和视图中定义的
PeopleSearchViewModel
相同。ActionResult函数必须与
Html.BeginForm
中的第一个参数匹配。请看这里的一个例子:不,对不起,这也是以前版本的一个拼写错误,现在更正了。在我的控制器上调用了正确的操作,但是模型没有通过。在Request.Forms对象中,参数作为key/val对存在<代码>人.名谢谢!这起作用了。在我看的教程中,它说这是它工作的必要条件。但也许里面没有一个文本框。。。我再看看。谢谢!这起作用了。在我看的教程中,它说这是它工作的必要条件。但也许里面没有一个文本框。。。我再看看。
@model PeopleSearchViewModel

@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
    @Html.LabelFor(m => m.Person.Firstname)
    @*@Html.HiddenFor(m => m.Person.Firstname)*@
    @Html.TextBoxFor(m => m.Person.Firstname)
    @Html.ValidationMessageFor(m => m.Person.Firstname)

    <input type="submit" value="Search" id="Whatever"/>
}