Solution:
Don't refer Nuget package components directly from the cshtml code. Instead, write an adapter calling static HtmlHelper extension methods from your custom extension methods with the same signature.
This approach has two advantages:
- First, it automatically suppresses CS1702.
- Secondly and above all, when you change used NuGet package, the compiler will notify you of the necessary link fixes (consisting perhaps only in changing the using command at the beginning of the cs code), while if you use NuGet component references directly from the cshtml code, run-time issues will appear.
I just verified this migrating from PagedList/PagedList.MVC to X.PagedList/X.PagedList.MVC.
namespace MyMvcExtensions
{
public static class MyHelperExtensions
{
...
public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction)
{
return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction);
}
public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, string inputFieldName)
{
return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, inputFieldName);
}
public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, X.PagedList.Mvc.Common.GoToFormRenderOptions options)
{
return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, options);
}
public static HtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl)
{
return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl);
}
public static HtmlString PagedListPager(this HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl, X.PagedList.Mvc.Common.PagedListRenderOptionsBase options)
{
return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl, options);
}
}
}
In your cshtml code write @using MyMvcExtensions instead of @using X.PagedList.Mvc.
If you will migrate to hypothetical Y.PagedList.MVC, compiler will alert you must do changes in your MyHelperExtensions class.