예제 #1
0
        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();

            // we should relay here on what was set with the {% model Model:... %} tag in the template
            // rather than what was set runtime in the "Model" context variable - they can differ
            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 = ProcessTag(htmlHelper, context, content, parms);

            if (result == null)
            {
                return("");
            }
            else
            {
                return(result.ToHtmlString());
            }
        }
예제 #2
0
        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));
            }
        }