Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public string Action <TController>(string action) where TController : BaseController
        {
            var url = UrlUtil.Action <TController>(action);
            HttpWebRequestHelper helper = new HttpWebRequestHelper();

            return(helper.GetContent(url));
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public string Action <TController>(string action, object datas) where TController : BaseController
        {
            var dic = 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('&');
            }
            HttpWebRequestHelper helper = new HttpWebRequestHelper();

            return(helper.GetContent(url));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 设置系统的默认页面,只能在Application_BeginRequest中调用此方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="application"></param>
        /// <param name="actionName"></param>
        public static void SetDefaultRoute <T>(this HttpApplication application, String actionName)
            where T : BaseController
        {
            var request = application.Request;
            var url     = UrlUtil.Action <T>(actionName);

            if (request.Url.AbsolutePath.EndsWith("/"))
            {
                HttpWebRequestHelper helper = new HttpWebRequestHelper();
                foreach (var key in HttpContext.Current.Request.Cookies.AllKeys)
                {
                    HttpCookie ck     = HttpContext.Current.Request.Cookies[key];
                    var        cookie = new System.Net.Cookie();
                    cookie.Name     = ck.Name;
                    cookie.Domain   = HttpContext.Current.Request.Url.Host;
                    cookie.Expires  = ck.Expires;
                    cookie.HttpOnly = ck.HttpOnly;
                    cookie.Path     = ck.Path;
                    cookie.Value    = ck.Value;
                    helper.CookieContainer.Add(cookie);
                }
                string content = null;
                try
                {
                    content = helper.GetContent(url);
                }
                catch (Exception)
                {
                    application.Response.Redirect(url);
                    return;
                }
                application.Response.Write(content);
                application.Response.StatusCode  = 200;
                application.Response.ContentType = "text/html";
                application.Response.Flush();
                application.Response.End();
            }
        }
Exemplo n.º 6
0
            public string SubmitTo <T>(string actionName, string parametersStr, string domID, string successDo, string errorDo)
                where T : BaseController
            {
                string url = UrlUtil.Action <T>(actionName);

                if (string.IsNullOrEmpty(successDo))
                {
                    successDo = string.Empty;
                }
                if (string.IsNullOrEmpty(errorDo))
                {
                    errorDo = string.Empty;
                }
                if (string.IsNullOrEmpty(parametersStr) == false)
                {
                    url += "?" + parametersStr;
                }
                successDo = System.Web.HttpUtility.HtmlEncode(successDo);
                errorDo   = System.Web.HttpUtility.HtmlEncode(errorDo);
                const string html = " MAjax='{0}' MUrl='{1}' MSuccessDo='{2}' ErrorDo='{3}' ";
                string       ret  = string.Format(html, domID, url, successDo, errorDo);

                return(ret);
            }
Exemplo n.º 7
0
        public static string Action <TController>(string action) where TController : BaseController
        {
            var url = UrlUtil.Action <TController>(action);

            return(url);
        }