I want to use partial on my web to show main slide but when i use partial i keep getting error. Help me please.
Here my some code:
On Controller
DataClasses1DataContext db = new DataClasses1DataContext();
public ActionResult TestSnew()
{
var snew = db.Snews;
return PartialView(snew);
}
On View
@model Jiremsenmn.Models.Snew
Some Html code to shown
On Layout
@Html.Partial("TestSnew")
You are sending a Model of Snews (plural) , when your view is expecting just one Snew.
Try this:
When you are in the context of a View, you are expected to have your information ready to be displayed.
You did that in your fist example PartialView(snew) when retrieving from your DB and sending it to the View.
But in your second example you are already on the view, so here you have to create your Snew object, so let’s suppose that Snew Class is simple and it has two properties, something like:
So within the context of your View, you have to populate the object yourself to send it to HtmlPartial, something like this:
NOTE make sure you reference the Snew class correctly with the using statement in your view
hope it helps,