[EDIT]MVC 4 Просмотр оленья кожа признать модель
@model LocationInfo (LocateIt.Models)
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
</div>
</body>
</html>
Я только начал работать с MVC/NHibernate сегодня, перейдя через небольшой учебник. Все прошло нормально, пока я не попытался создать представление из своей модели с помощью ActionResult (Index). Кажется, что взгляд не может найти модель, и поскольку я буквально новичок, я понятия не имею, что делать.
Не могли бы вы, ребята, взглянуть на мой код и рассказать мне, что я сделал неправильно или хотя бы дать ключ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LocateIt.Models
{
public class LocationInfo
{
public virtual int Id { get; set; }
public virtual string LocationName { get; set; }
public virtual string LocationDescription { get; set; }
public virtual string City { get; set; }
public virtual string Street { get; set; }
public virtual string HouseNumber { get; set; }
public virtual short PLZ { get; set; }
public virtual decimal Rating { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LocateIt.Models;
using LocateIt.Models.NHibernate;
namespace LocateIt.Controllers
{
public class LocationInfoController : Controller
{
LocationInfoRepository _repository;
public LocationInfoController()
{
_repository = new LocationInfoRepository();
}
public ActionResult Index()
{
IList<LocationInfo> LocationInfo = _repository.GetLocation("Oberhausen");
return View(LocationInfo);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Linq;
namespace LocateIt.Models.NHibernate
{
public class LocationInfoRepository
{
public IList<LocationInfo> GetLocation(string city)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return session.Query<LocationInfo>().ToList();
}
}
public void Save(LocationInfo objLocationInfo)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(objLocationInfo);
transaction.Commit();
}
}
}
}
}
using NHibernate;
using NHibernate.Cfg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LocateIt.Models.NHibernate
{
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
var NHibernateConfig = new Configuration();
NHibernateConfig.Configure(HttpContext.Current.Server.MapPath(
@"Models\NHibernate\Configuration\hibernate.cfg.xml"));
NHibernateConfig.AddDirectory(new System.IO.DirectoryInfo(
HttpContext.Current.Server.MapPath(@"Models\NHibernate\Mappings")));
_sessionFactory = NHibernateConfig.BuildSessionFactory();
}
return _sessionFactory;
}
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="MVC4_Using_NHB"
namespace="MVC4_Using_NHB"
auto-import="true">
<class name="MVC4_Using_NHB.Models.LocationInfo,MVC4_Using_NHB">
<id name="Id" access="property" column="Id" type="Int32">
<generator class="native"></generator>
</id>
<property name="LocationName" access="property"
column="LocationName" type="String"></property>
<property name="LocationDescription" access="property"
column="LocationDescription" type="String"></property>
<property name="City" access="property"
column="City" type="String"></property>
<property name="Street" access="property"
column="Street" type="String"></property>
<property name="HouseNumber" access="property"
column="HouseNumber" type="String"></property>
<property name="PLZ" access="property"
column="PLZ" type="Int16"></property>
<property name="Rating" access="property"
column="Rating" type="Int32"></property>
</class>
</hibernate-mapping>
Что делает "It кажется, что взгляд не может найти модель «означает? Вы получаете какую-либо ошибку компиляции или исключение времени выполнения? Что происходит (или не происходит), что заставляет вас думать, что что-то не так? – nemesv
Я получаю сообщение об ошибке: «имя« модель »не существует в текущем контексте» внутри представления. – OhSnap
Возможно, вы перепутали представление. Представление, которое вы разместили, похоже на макет, но похоже, что вы пытались использовать его как представление. Как называется этот файл? –