Consider a ViewComponent that renders paging navigation. One of the parameters passed to the component is the current PageIndex (index of the viewed page).
How can I use this passed value in my ViewComponents template without putting it into the ViewData?
-- ViewComponent:
[ComponentName("GalleryPager")]
public class PagerComponent : ViewComponent
{
[Parameter("PageIndex")]
private int _pageIndex;
public void Run()
{
... some logic ...
ViewData["PageIndex"] = _pageIndex; // I want to avoid this!
}
}
-- Parent view:
...
<span class="paging">
{% GalleryPager @PageIndex = SOME_VALUE %}
</span>
...
-- Component view:
...
<span class="page_index">
{{ PageIndex }} <!-- This way it's passed/used as ViewData -->
</span>
...