Пример #1
0
        public MvcForm BeginForm <TController>(string action, RequestType formType, object htmlAttributes) where TController : BaseController
        {
            var url = UrlUtil.Action <TController>(action);
            var dic = MHtmlHelper <object> .AnonymousObjectToHtmlAttributes(htmlAttributes);

            var name = typeof(TController).Name + "_form";

            if (dic.ContainsKey("id") == false)
            {
                dic["id"] = name;
                if (dic.ContainsKey("name") == false)
                {
                    dic["name"] = name;
                }
            }
            else
            {
                if (dic.ContainsKey("name") == false)
                {
                    dic["name"] = dic["id"];
                }
                else
                {
                    dic["name"] = name;
                }
            }
            string otherInfo = ConvertIDictionaryToHtml(dic);
            string formInfo  = "<form   method='{0}' action='{1}'  {2}>" + Environment.NewLine;

            formInfo = string.Format(formInfo, formType.ToString(), url, otherInfo);
            var ret = new MvcForm(formInfo, _context);

            return(ret);
        }
Пример #2
0
 public override void SetModel(object model)
 {
     this.Model = (TModel)model;
     if (model != null)
     {
         _ModelType = model.GetType();
         Html       = new MHtmlHelper <TModel>(this.Model, this.Context);
     }
 }
Пример #3
0
        public static string Action <TController>(string action, object datas) where TController : BaseController
        {
            var dic = MHtmlHelper <object> .AnonymousObjectToHtmlAttributes(datas);

            var url = UrlUtil.Action <TController>(action);

            if (dic.Count > 0)
            {
                url = url + "?";
                foreach (var kvp in dic)
                {
                    url += kvp.Key + "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()) + "&";
                }
                url = url.TrimEnd('&');
            }
            return(url);
        }