此示例显示了在使用的情况下如何实现它。ASP.NET MVC/Core
如果您不想使用dynamic
,则可以在is..as
链上替换它。
public class ProductController : Controller
{
public ViewResult Product(long productId)
{
var product = FindProduct(productId);
var productView = GetRelevantProductView((dynamic)product);
return productView;
}
private void GetRelevantProductView(Book book)
{
return View("BookView", book);
}
private void GetRelevantProductView(Game game)
{
return View("GameView", game);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句