Module view component
What is it ?
A module view component is a MVC view component specific to Kastra. It is called by the Kastra template if a module is created on the page which uses the template.
How to create one ?
To make a view component module, you can use the Kastra.Core.ViewComponents namespace. Your view component must derive from ModuleViewComponent class. You can use a model which must derive from ModuleModelBinder class.
An example could be :
IndexViewComponent.cs
namespace Kastra.Module.Article
{
[ViewComponent(Name = "Kastra.Module.Article.Index")]
public class IndexViewComponent : ModuleViewComponent
{
private readonly ArticleContext _dbContext = null;
private readonly IArticleBusiness _articleManager = null;
public ArticleViewComponent(ArticleContext dbContext, IArticleBusiness articleBusiness)
{
_dbContext = dbContext;
_articleManager = articleBusiness;
}
public override ViewViewComponentResult OnViewComponentLoad()
{
IndexModel model = new IndexModel(this);
// Fill the model or do other thing here ...
return ModuleView("Index", model);
}
}
}
IndexModel.cs
namespace Kastra.Module.Article.Models
{
public class IndexModel: ModuleModelBinder
{
public IndexModel(ModuleViewComponent moduleView) : base(moduleView) { }
public IList<articleinfo> Articles { get; set; }
public Int32 PageId { get; set; }
}
}
It is posible to create a module view component for your module settings. The link to this view component will be available in the administration panel. For more information, please refer to the next section of the documentation.