本文整理汇总了C#中HtmlHelper.Partial方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.Partial方法的具体用法?C# HtmlHelper.Partial怎么用?C# HtmlHelper.Partial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.Partial方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderPopup
public static MvcHtmlString RenderPopup(HtmlHelper helper, TypeContext typeContext, RenderPopupMode mode, EntityBase line, bool isTemplate = false)
{
TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext);
ViewDataDictionary vdd = GetViewData(helper, line, tc);
string partialViewName = line.PartialViewName ?? OnPartialViewName(tc);
vdd[ViewDataKeys.PartialViewName] = partialViewName;
vdd[ViewDataKeys.ViewMode] = !line.ReadOnly;
vdd[ViewDataKeys.ViewMode] = ViewMode.View;
vdd[ViewDataKeys.ShowOperations] = true;
vdd[ViewDataKeys.SaveProtected] = OperationLogic.IsSaveProtected(tc.UntypedValue.GetType());
vdd[ViewDataKeys.WriteEntityState] =
!isTemplate &&
!(tc.UntypedValue is EmbeddedEntity) &&
((ModifiableEntity)tc.UntypedValue).Modified == ModifiedState.SelfModified;
switch (mode)
{
case RenderPopupMode.Popup:
return helper.Partial(Navigator.Manager.PopupControlView, vdd);
case RenderPopupMode.PopupInDiv:
return helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
helper.Partial(Navigator.Manager.PopupControlView, vdd),
"",
new Dictionary<string, object> { { "style", "display:none" } });
default:
throw new InvalidOperationException();
}
}
示例2: RenderContent
public static MvcHtmlString RenderContent(HtmlHelper helper, TypeContext typeContext, RenderContentMode mode, EntityBase line)
{
TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext);
ViewDataDictionary vdd = GetViewData(helper, line, tc);
string partialViewName = line.PartialViewName ?? OnPartialViewName(tc);
switch (mode)
{
case RenderContentMode.Content:
return helper.Partial(partialViewName, vdd);
case RenderContentMode.ContentInVisibleDiv:
return helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
helper.Partial(partialViewName, vdd), "",
null);
case RenderContentMode.ContentInInvisibleDiv:
return helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
helper.Partial(partialViewName, vdd), "",
new Dictionary<string, object> { { "style", "display:none" } });
default:
throw new InvalidOperationException();
}
}
示例3: Render
public static IHtmlString Render(string alias, HtmlHelper<RenderModel> helper)
{
try
{
// If request is coming from frontend then always show frontend content, check authentication if it comes from backend (.aspx)
var isAuthenticated = false;
if (HttpContext.Current.Request.Path.Contains(".aspx"))
{
isAuthenticated = Authorize.isAuthenticated();
}
var view = ViewHelper.Get(alias, isAuthenticated);
var culture = CultureInfo.CreateSpecificCulture(UmbracoContext.Current.PublishedContentRequest.Culture.Name);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
var model = helper.Partial(view.viewName, view);
return new HtmlString(model.ToString());
}
catch (Exception ex)
{
Log.Error("Canvas Error on Render in API.", ex);
return new HtmlString("");
}
}
示例4: RenderThemeCustomPartial
private static IHtmlString RenderThemeCustomPartial(HtmlHelper helper, string viewPathToFormat)
{
string themeName = new LayersCmsConfigHelper().GetTheme();
string viewPath = string.Format(viewPathToFormat, themeName);
string filePath = HttpContext.Current.Server.MapPath(String.Format("~/views/shared/{0}.cshtml", viewPath));
if (File.Exists(filePath))
{
return helper.Partial(viewPath);
}
return null;
}
示例5: Render
public string Render(HtmlHelper html)
{
try
{
return html.Partial(Macro.ScriptName, html.ViewData).ToHtmlString();
}
catch(Exception ex)
{
return HttpUtility.HtmlEncode(ex.ToString());
}
}
示例6: Menu
public static MvcHtmlString Menu(this HtmlHelper helper)
{
server = helper.ViewContext.RequestContext.HttpContext.Server;
request = helper.ViewContext.RequestContext.HttpContext.Request;
urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
routeDictionary = helper.ViewContext.RequestContext.RouteData.Values;
HtmlHelper htmlHelper = new HtmlHelper(helper.ViewContext, helper.ViewDataContainer);
//获取当前用户信息
//TalentMISDbContext db = new TalentMISDbContext();
//string current_account = helper.ViewContext.RequestContext.HttpContext.User.Identity.Name;
//Account account = db.Accounts.FirstOrDefault(x => x.UserName.Trim().ToUpper() == current_account.Trim().ToUpper());
//string roleCode = account.RoleCode;
string roleCode = ((CurrentUser)helper.ViewContext.RequestContext.HttpContext.Session["CurrentUser"]).RoleCode;
//加载菜单xml文件
//string xmlPath = server.MapPath(url.Content("~/Menu.xml"));//当禁用Cookie时会话标识会嵌入URL中,此时该行代码结果就不正确了!(夏春涛)
string webRootPath = server.MapPath("/");
string xmlPath = webRootPath.TrimEnd('\\') + "\\Menu.xml";
XDocument doc = XDocument.Load(xmlPath);
var xmlNav = doc.Root;
//获取所有符合条件的一级菜单(其中包括所有二级菜单)
var nav1Items = xmlNav
.Elements("NavItem")
.Where(p => p.Attribute("roles").Value.Trim() == "" ||
p.Attribute("roles").Value.Trim().ToUpper().Contains(roleCode.ToUpper()));
foreach (var nav1 in nav1Items)
{
//删除一级菜单下不符合条件的二级菜单
var nav2List = nav1.Elements("NavItem").ToList();
foreach (var nav2 in nav2List)
{
if (nav2.Attribute("roles").Value.Trim() == "")//任意角色均可访问的二级菜单
{
continue;
}
bool isPermitted = nav2.Attribute("roles").Value.ToUpper().Contains(roleCode.Trim().ToUpper());
if (!isPermitted)//用户角色不再许可范围内
{
nav1.Elements("NavItem")
.Where(p => p.Attribute("code").Value.Trim().ToUpper() == nav2.Attribute("code").Value.Trim().ToUpper())
.Remove();
}
}
}
//如果一级菜单下面没有二级菜单,则删除该一级菜单
nav1Items.Where(p => p.Elements().Count() == 0).Remove();
//----
MvcHtmlString result = htmlHelper.Partial("Menu", nav1Items);
return result;
}
示例7: CachedPartialView
/// <summary>
/// Outputs and caches a partial view in MVC
/// </summary>
/// <param name="cacheHelper"></param>
/// <param name="htmlHelper"></param>
/// <param name="partialViewName"></param>
/// <param name="model"></param>
/// <param name="cachedSeconds"></param>
/// <param name="cacheKey">used to cache the partial view, this key could change if it is cached by page or by member</param>
/// <param name="viewData"></param>
/// <returns></returns>
public static IHtmlString CachedPartialView(
this CacheHelper cacheHelper,
HtmlHelper htmlHelper,
string partialViewName,
object model,
int cachedSeconds,
string cacheKey,
ViewDataDictionary viewData = null)
{
return cacheHelper.GetCacheItem(
PartialViewCacheKey + cacheKey,
CacheItemPriority.NotRemovable, //not removable, the same as macros (apparently issue #27610)
null,
new TimeSpan(0, 0, 0, cachedSeconds),
() => htmlHelper.Partial(partialViewName, model, viewData));
}
示例8: RenderPager
/// <summary>
/// 生成最终的分页Html代码
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="pagedable"></param>
/// <param name="pagingTemplatePartialName"></param>
/// <returns></returns>
private static MvcHtmlString RenderPager(HtmlHelper htmlHelper, IPagedable pagedable, string pagingTemplatePartialName)
{
if (pagedable.PageNumber <= 0)
{
pagedable.PageNumber = 1;
}
if (pagedable.PageNumber > 0 && pagedable.PageNumber >= pagedable.PageCount)
{
pagedable.PageNumber = pagedable.PageCount;
}
var templateHtml = htmlHelper.Partial(pagingTemplatePartialName, pagedable);
if (templateHtml == null)
throw new ArgumentException(pagingTemplatePartialName);
return templateHtml;
}
示例9: GenerateHtmlFromPartialWithPrefix
/// <summary>
/// Contains functionality to parse template to html with needed
/// for razor attributes to have ability send data to main model
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="partialViewName">Template for html generation</param>
/// <param name="model">Model for data binding</param>
/// <param name="prefix">Prefix for input fields</param>
/// <param name="useModelProperties">Define if needed compare attributes with model property names</param>
public static string GenerateHtmlFromPartialWithPrefix(HtmlHelper htmlHelper, string partialViewName, object model, string prefix, bool useModelProperties = true)
{
var partialHtml = htmlHelper.Partial(partialViewName, model).ToHtmlString();
var res = "";
var properties = model.GetType().GetProperties().Select(s => s.Name);
if (useModelProperties)
{
var doc = new HtmlDocument();
doc.LoadHtml(partialHtml);
AddPrefix(doc, prefix, properties);
res = doc.DocumentNode.InnerHtml;
}
else
{
partialHtml = ReplaceTagWithPrefix(partialHtml, "textarea", prefix, true);
partialHtml = ReplaceTagWithPrefix(partialHtml, "input", prefix, false);
res = partialHtml;
}
return res;
}
示例10: GetTypedGridHtml
/// <summary>
/// Gets the HTML for the Grid model.
/// </summary>
/// <param name="content">The parent content item.</param>
/// <param name="html">The instance of <code>HtmlHelper</code>.</param>
/// <param name="propertyAlias">The alias of the property.</param>
/// <param name="framework">The framework used to render the Grid.</param>
public static HtmlString GetTypedGridHtml(this IPublishedContent content, HtmlHelper html, string propertyAlias, string framework) {
// Get the property with the specifeid alias
IPublishedProperty property = content.GetProperty(propertyAlias);
if (property == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);
// Get the property value
GridDataModel value = property.Value as GridDataModel;
if (value == null) return new HtmlString(String.Empty);
// Load the partial view based on the specified framework
return html.Partial("TypedGrid/" + framework, property.Value);
}
示例11: Transform
public IHtmlString Transform(HtmlHelper htmlHelper, INode node, string html)
{
var propertyVm = node.ToPropertyVm();
var partialViewName = htmlHelper.BestViewName(propertyVm.Type, "FormFactory/Property.");
return htmlHelper.Partial(partialViewName, propertyVm);
}
示例12: WriteFilter
public override System.Web.Mvc.MvcHtmlString WriteFilter(HtmlHelper helper, object htmlAttributes)
{
IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
AddCommonHtmlAttributes(efHtmlAttributes);
return helper.Partial(PartialViewName, this);
}
示例13: ToHtml
public MvcHtmlString ToHtml(HtmlHelper helper)
{
return helper.Partial(DashboardClient.ViewPrefix.FormatWith("DashboardView"), Dashboard,
new ViewDataDictionary { { "currentEntity", Entity } });
}
示例14: Render
public MvcHtmlString Render(HtmlHelper helper)
{
return helper.Partial("NavigationBar");
}
示例15: Render
public string Render(HtmlHelper html)
{
//UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
return html.Partial(Macro.ScriptName, null).ToHtmlString();//UmbracoContext.Current.PublishedContentRequest.PublishedContent)).ToHtmlString();
}