C# 如何在MVC4中返回值

C# 如何在MVC4中返回值,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,如何修复此错误 传递到字典的模型项的类型为“System.Security.Principal.GenericPrincipal”,但此字典需要类型为“MvcbetaSite.Models.RegClass”的模型项 public ActionResult寄存器(RegClass NewUser) { if(ModelState.IsValid) { 尝试 { 使用(DBClassesDataContext DB=new DBClassesDataContext()) { var name=Ne

如何修复此错误

传递到字典的模型项的类型为“System.Security.Principal.GenericPrincipal”,但此字典需要类型为“MvcbetaSite.Models.RegClass”的模型项

public ActionResult寄存器(RegClass NewUser)
{
if(ModelState.IsValid)
{
尝试
{
使用(DBClassesDataContext DB=new DBClassesDataContext())
{
var name=NewUser.name;
ModelState.Clear();
DB.Dispose();
ViewBag.Message=名称;
}
}
捕获(例外情况除外)
{
ViewBag.Message=示例消息;
}
}
返回视图(用户);
}
注册类

@model MvcbetaSite.Models.RegClass

@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)

@Html.EditorFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)

用户是您指定的System.Security.Principal.GenericPrincipal类型

@model MvcbetaSite.Models.RegClass
在视图中。您的视图需要的是MvcbetaSite.Models.RegClass,而不是System.Security.Principal.GenericPrincipal。

带有

return View(User);
您正在将一个全局变量传递到视图中(该变量来自
System.Security.Principal.GenericPrincipal
命名空间)

您可能要做的是将
newUser
变量传递到视图中(这是视图所期望的类型)


我想要保存在sql中(linQ to sql)var DB=new DataClasses1DataContext();DB.Psave(NewUser.Name,NewUser.LastName);你的问题缺乏任何你想做什么的信息。你基本上是说“这是代码,修复它”。这里不应该这样问问题。请看,我确切地告诉了你为什么会这样。不要将@model指定为RegClass
@model MvcbetaSite.Models.RegClass