From my controller I'm sending localized view name like
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
string viewName = string.Empty;
switch (currentCulture)
{
case "en-US":
viewName = "en-US.cshtml";
break;
case "de-DE":
viewName = "de-DE.cshtml";
break;
case "fr-FR":
viewName = "fr-FR.cshtml";
break;
default:
}
ViewBag.LocView = "~/Views/Home/"+viewName;
and inside view I want to display using partial like
@Html.Partial(@ViewBag.LocView);
but this obviously is not ok since I'm getting
'System.Web.Mvc.HtmlHelper' has not applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
ViewBag的类型不是很强, @Html.Partial
需要一个字符串,因此您应该能够:
@Html.Partial((string)@ViewBag.LocView);
调用ViewBag时,需要将其转换为字符串数据类型
@Html.Partial((string)@ViewBag.LocView)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.