public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms) { var htmlHelperOption = context.tryfind("Html"); if (htmlHelperOption == null) return ""; var htmlHelper = (HtmlHelper)htmlHelperOption.Value; var string_writer = new StringWriter(); var writer = htmlHelper.ViewContext.Writer; try { htmlHelper.ViewContext.Writer = string_writer; var form = htmlHelper.BeginForm(); string_writer.Flush(); var start = string_writer.ToString(); string_writer = new StringWriter(); htmlHelper.ViewContext.Writer = string_writer; form.EndForm(); string_writer.Flush(); var end = string_writer.ToString(); return start + content + end; } finally { htmlHelper.ViewContext.Writer = writer; } }
public override string GenerateUrl(string pathTemplate, string[] parameters, NDjango.Interfaces.IContext context) { var htmlHelperOption = context.tryfind("Html"); if (htmlHelperOption == null) return ""; var htmlHelper = (HtmlHelper)htmlHelperOption.Value; var anchor = LinkExtensions.ActionLink(htmlHelper, pathTemplate, pathTemplate, parameters[0]).ToHtmlString(); //retriving relativePath from anchor element. var startindex = anchor.IndexOf("href") + 6; var endIndex = anchor.IndexOf("\"", startindex); return anchor.Substring(startindex, endIndex - startindex); }
public override string GenerateUrl(string pathTemplate, string[] parameters, NDjango.Interfaces.IContext context) { var contextOption = context.tryfind(NDjangoView.aspmvcContextKey); if (contextOption == null || contextOption.Value == null) throw new ApplicationException("Unable to locate asp mvc request context. Did someone modify djangocontext." + NDjangoView.aspmvcContextKey + "?"); RequestContext requestContext = contextOption.Value as RequestContext; if (parameters.Length > 1) throw new ApplicationException("Only 0 or 1 parameters are supported by the asp.mvc version of the URL tag"); else if (parameters.Length == 1) return new UrlHelper(requestContext).Action(pathTemplate, parameters[0]); else return new UrlHelper(requestContext).Action(pathTemplate); }
public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms) { var htmlHelperOption = context.tryfind("Html"); if (htmlHelperOption == null) return ""; var htmlHelper = (HtmlHelper)htmlHelperOption.Value; var string_writer = new StringWriter(); var writer = htmlHelper.ViewContext.Writer; try { htmlHelper.ViewContext.Writer = string_writer; htmlHelper.RenderPartial(parms[0].ToString()); string_writer.Flush(); } finally { htmlHelper.ViewContext.Writer = writer; } return string_writer.ToString(); }
public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms) { var htmlHelperOption = context.tryfind("Html"); if (htmlHelperOption == null) return ""; var htmlHelper = (HtmlHelper)htmlHelperOption.Value; var metadata_provider = new DataAnnotationsModelMetadataProvider(); if (context.ModelType == null) htmlHelper.ViewData.ModelMetadata = null; else { var model = Activator.CreateInstance(context.ModelType.Value); htmlHelper.ViewData.ModelMetadata = metadata_provider.GetMetadataForType(() => model, context.ModelType.Value); } var result = htmlHelper.Label(parms[0].ToString()); if (result == null) return ""; else return result.ToHtmlString(); }