I have a model called "Slider"
using System;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
namespace BarMotors.Models
{
public class Slider
{
public virtual int Id { get; set; }
public virtual string Photo{ get; set; }
public virtual string LeftText{ get; set; }
public virtual string RightText { get; set; }
public virtual int SortOrder{ get; set; }
public virtual DateTime CreatedAt { get; set; }
public virtual DateTime? UpdatedAt { get; set; }
public virtual DateTime? DeletedAt { get; set; }
public virtual bool IsDeleted
{
get { return DeletedAt != null; }
}
}
public class SliderMap : ClassMapping<Slider>
{
public SliderMap()
{
Table("Sliders");
Id(x => x.Id, x => x.Generator(Generators.Identity));
Property(x => x.Photo, x => x.NotNullable(true));
Property(x => x.LeftText);
Property(x => x.RightText);
Property(x => x.SortOrder, x => x.NotNullable(true));
}
}
}
I also (now) have this controller;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using BarMotors.Models;
using NHibernate.Linq;
namespace BarMotors.Controllers
{
public class SliderController : Controller
{
[ChildActionOnly]
public ActionResult Sliders()
{
List<Slider> model;
new List<Models.Slider>();
model = Database.Session.Query<Slider>().Where(s => s.DeletedAt == null).OrderBy(x=>x.SortOrder).ToList();
return PartialView("_HomeSlider", model);
}
}
}
MAIN view
@{
ViewBag.Title = "Homepage";
}
<h1>Homepage</h1>
@Html.Action("Sliders", "Slider")
Partial view
@model BarMotors.Models.Slider
@{
Layout = null;
}
//do something in loop of Slider
In SliderController I cannot pass var model to the partial view I either get Iqueryable, ienumerable or errors along the lines of;
LIST of Models.Slider is not assignable to type models.Slider
Many thanks Simon