2015-09-12 3 views
0

Я новичок в Asp.net mvc 4. Я создал класс в разделе Model, его имя - «Пользователь». Затем я создал объект этого класса и отправил его в одно представление. Я добавил «@model projectName.Model.User» в часть «Просмотр». После выполнения этой ошибки была показана ошибка (Ошибка сервера в приложении «/»). Как я могу справиться с этим? большое спасибо.Ошибка сервера в '/' приложении в Asp.net mvc 4

namespace Sprint1.Controllers 
{ 
    public class LoginController : Controller 
    { 
     // 
     // GET: /Login/ 

     public ActionResult Index() 
     { 
      Models.User Ouser = new User(); 
      return View(User); 
     } 
     [HttpPost] 
     public ActionResult SignUp() 
     { 
      return View(); 
     }   
    } 
} 

Эта часть является моим представлением для первого действия.

@model Sprint1.Models.User 
@{ 
    ViewBag.Title = "Index"; 
    Layout = "~/Views/Shared/Layouts/_LayoutPage.cshtml"; 
} 

<h2>Login Page</h2> 

@using (Html.BeginForm("SignUp", "Login", FormMethod.Post)) 
{ 

    <fieldset> 
     <legend> Login</legend> 
     <p> 

      <label for="Name">Name:</label> 
      @Html.TextBoxFor(User => User.name) 


     </p> 


     <p> 
      <input type="submit" id="submit" value="submit" onclick=return("~/Views/SignUp") /> 
     </p> 

    </fieldset> 


} 

И страница ошибки:

Server Error in '/' Application.

The model item passed into the dictionary is of type 'System.Security.Principal.WindowsPrincipal', but this dictionary requires a model item of type 'Sprint1.Models.User'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Security.Principal.WindowsPrincipal', but this dictionary requires a model item of type 'Sprint1.Models.User'.

Источник ошибки:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

+0

Пожалуйста, отправьте Ваше мнение и действия. Также отправьте сообщение об ошибке. –

+0

Тогда каково сообщение об ошибке? Просьба добавить свой ответ, не ставьте в награду. –

+0

Вопрос был исправлен. –

ответ

0

В вашем методе индекс действия заменить View(User) с View(Ouser)

public ActionResult Index() 
{ 
    Models.User Ouser = new User(); 
    // User is a property in your controller with type of `IPrincipal` 
    // But your new user variable name is Ouser; 
    //return View(User); 

    return View(Ouser); 

} 
Смежные вопросы