• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mvc.ActionResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Mvc.ActionResult的典型用法代码示例。如果您正苦于以下问题:C# ActionResult类的具体用法?C# ActionResult怎么用?C# ActionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ActionResult类属于System.Web.Mvc命名空间,在下文中一共展示了ActionResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ActionLinkWithFragment

        public static MvcHtmlString ActionLinkWithFragment(this HtmlHelper htmlHelper, string text, ActionResult fragmentAction, string cssClass = null, string dataOptions = null)
        {
            var mvcActionResult = fragmentAction.AsMVCResult() as IMvcResult;

            if (mvcActionResult == null)
                return null;

            var options = string.Empty;

            var actionLink = string.Format("{0}#{1}",
                        RouteTable.Routes.GetVirtualPathForArea(htmlHelper.ViewContext.RequestContext,
                                                        new RouteValueDictionary(new
                                                        {
                                                            area = string.Empty,
                                                            controller = mvcActionResult.Controller,
                                                            action = string.Empty,
                                                        })).VirtualPath,
                         mvcActionResult.Action);

            if (!string.IsNullOrEmpty(dataOptions))
                options = "data-options=\"" + dataOptions.Trim() + "\"";

            return new MvcHtmlString(string.Format("<a id=\"{0}\" href=\"{1}\" class=\"jqAddress {2}\" {3}>{4}</a>", Guid.NewGuid(), actionLink,
                (string.IsNullOrEmpty(cssClass) ? string.Empty : cssClass.Trim()),
                (string.IsNullOrEmpty(options) ? string.Empty : options.Trim()), text));
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:26,代码来源:HtmlHelperExtension.cs


示例2: AssertStatusCodeResult

 private static void AssertStatusCodeResult(ActionResult result, int statusCode, string statusDesc)
 {
     Assert.IsType<HttpStatusCodeWithBodyResult>(result);
     var httpStatus = (HttpStatusCodeWithBodyResult)result;
     Assert.Equal(statusCode, httpStatus.StatusCode);
     Assert.Equal(statusDesc, httpStatus.StatusDescription);
 }
开发者ID:jrolstad,项目名称:NuGetGallery,代码行数:7,代码来源:ApiControllerFacts.cs


示例3: NavActionLink

        /// <summary>
        /// Creates a Navigation action link inside an li tag that highlights based on which page you're on.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="actionResult">The action result.</param>
        /// <returns></returns>
        public static MvcHtmlString NavActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult actionResult)
        {
            var result = actionResult.GetT4MVCResult();

            var li = new TagBuilder("li");

            // create anchor tag
            var anchor = HtmlHelper.GenerateLink(
                    htmlHelper.ViewContext.RequestContext,
                    RouteTable.Routes,
                    linkText,
                    "",
                    result.Action,
                    result.Controller,
                    result.RouteValueDictionary,
                    null);

            // add anchor tag to li tag
            li.InnerHtml = anchor;

            // get the route data
            var controller = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue as string;
            var action = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue as string;
            if (result.Action == action && result.Controller == controller)
            {
                li.MergeAttribute("class", "active");
            }

            return MvcHtmlString.Create(li.ToString());
        }
开发者ID:Cartman380,项目名称:CruisinForChildren,代码行数:37,代码来源:HtmlHelperExtensions.cs


示例4: ReturnRoute

 public ActionResult ReturnRoute(int? id, ActionResult defaultRoute)
 {
     RouteValueDictionary routeValues = new RouteValueDictionary();
     switch (GetRouteParameter())
     {
         case "c-tls":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "TracksLocationsSlots";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "c-ss":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "SessionsSpeakers";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "c-m":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "Manage";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "s-v":
             routeValues["controller"] = "Session";
             routeValues["action"] = "View";
             routeValues.Add("conferenceId", ControllerContext.HttpContext.Request.Params["ConferenceId"]);
             routeValues.Add("SessionId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
     }
     return defaultRoute;
 }
开发者ID:EPTamminga,项目名称:Conference,代码行数:29,代码来源:ConferenceMvcController.cs


示例5: Form

 public Form(ActionResult result) : base(result)
 {
     _routeValues = new RouteValueDictionary();
     _result = result;
     _formMethod = System.Web.Mvc.FormMethod.Post;
     _actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
开发者ID:CodeBlueDev,项目名称:TwitterBootstrapMVC.ExtensionPatch,代码行数:7,代码来源:Form.cs


示例6: Form

 public Form(ActionResult result)
     : base(null)
 {
     this._result = result;
     this._formMethod = System.Web.Mvc.FormMethod.Post;
     _actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:7,代码来源:Form.cs


示例7: AssertIsView

 protected void AssertIsView(ActionResult result, string viewName)
 {
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(typeof(ViewResult), result);
     var view = (ViewResult)result;
     Assert.AreEqual(viewName, view.ViewName);
 }
开发者ID:liammclennan,项目名称:shortest-path,代码行数:7,代码来源:BaseSpec.cs


示例8: HasError

 public static void HasError(ActionResult result, int index, string field, string message)
 {
     var view = (ViewResult)result;
     var error = ((IList<ValidationError>)view.ViewData["ValidationErrors"])[index];
     Assert.Equal(field, error.Field);
     Assert.Equal(message, error.Message);
 }
开发者ID:okeulder,项目名称:codebettercanvas,代码行数:7,代码来源:BaseControllerTests.cs


示例9: IsFile

        public static void IsFile(ActionResult actionResult, string fileName)
        {
            GenericAssert.InstanceOf<FileStreamResult>(actionResult);

            var fileStreamResult = (FileStreamResult)actionResult;
            GenericAssert.AreEqual(fileName, fileStreamResult.FileDownloadName);
        }
开发者ID:Proligence,项目名称:OrchardTesting,代码行数:7,代码来源:AssertActionResult.cs


示例10: IsRedirect

        public static void IsRedirect(ActionResult actionResult, string targetUrl)
        {
            GenericAssert.InstanceOf<RedirectResult>(actionResult);

            var redirectResult = (RedirectResult)actionResult;
            GenericAssert.AreEqual(targetUrl, redirectResult.Url);
        }
开发者ID:Proligence,项目名称:OrchardTesting,代码行数:7,代码来源:AssertActionResult.cs


示例11: GetUrl

 public static string GetUrl(this HtmlHelper html, ActionResult actionResult)
 {
     if (actionResult == null) throw new ArgumentNullException("actionResult");
     RouteValueDictionary routeValueDictionary = actionResult.GetRouteValueDictionary();
     return UrlHelper.GenerateUrl(null, null, null, routeValueDictionary, html.RouteCollection,
                           html.ViewContext.RequestContext, false);
 }
开发者ID:madaboutcode,项目名称:Chronicles,代码行数:7,代码来源:HtmlHelperExtensions.cs


示例12: ActionImage

        public static MvcHtmlString ActionImage(this HtmlHelper html, ActionResult action, Image image, int size = 100, string genericPath = null)
        {
            string path;
            string alt;
            if (image != null)
            {
                path = image.Url;
                alt = image.AltText;
            }
            else
            {
                path = genericPath;
                alt = string.Empty;
            }

            var url = new UrlHelper(html.ViewContext.RequestContext);

            // build the <img> tag
            var imgBuilder = new TagBuilder("img");
            imgBuilder.MergeAttribute("src", url.Content(path));
            imgBuilder.MergeAttribute("alt", alt);
            imgBuilder.MergeAttribute("height", size.ToString());
            string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);

            // build the <a> tag
            var anchorBuilder = new TagBuilder("a");
            anchorBuilder.MergeAttribute("href", url.Action(action));
            anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
            string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);

            return MvcHtmlString.Create(anchorHtml);
        }
开发者ID:MosheTech,项目名称:Trial,代码行数:32,代码来源:HtmlHelperExtensions.cs


示例13: GoToActivityList

        public void GoToActivityList()
        {
            var controller = CreateActivityController();

            var actionResult = controller.Index();          // No assert in the Given & When steps, please
            LatestActionResult = actionResult;
        }
开发者ID:KimmoKer,项目名称:ProgressiveNetDemos,代码行数:7,代码来源:ActivitiesControllerSteps.cs


示例14: ValidateUserNamePasswordLogin

 private bool ValidateUserNamePasswordLogin(LoginModel login, string redirectUrl, out ActionResult redirect)
 {
     try
     {
         if (authProvider.Authenticate(login.Name, login.UserName, login.Password))
         {
             redirect = Redirect(redirectUrl);
             return true;
         }
     }
     catch (InvalidCredentialsException)
     {
         ModelState.AddModelError("", "Invalid user name or password");
         RedirectToAction("Fail");
     }
     catch (UserNotAuthenticatedException)
     {
         ModelState.AddModelError("", "User could not be identified");
         RedirectToAction("Fail");
     }
     catch (UnsupportedAuthenticationType)
     {
         ModelState.AddModelError("", "Authentication mode not supported");
         RedirectToAction("Fail");
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Something went wrong");
         redirect = View();
         return true;
     }
     redirect = View();
     return false;
 }
开发者ID:robzelt,项目名称:IntroMvcDemo,代码行数:34,代码来源:LoginController.cs


示例15: BootstrapActionLink

 public BootstrapActionLink(HtmlHelper html, string linkText, ActionResult result)
 {
     this.html = html;
     this._linkText = linkText;
     this._result = result;
     this._actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
开发者ID:joypipi,项目名称:TwitterBootstrapMvc,代码行数:7,代码来源:BootstrapActionLink.cs


示例16: LoginResult

 private LoginResult(bool successful, string errorMessage, string accessToken, ActionResult defaultLoginAction)
 {
     Successful = successful;
     ErrorMessage = errorMessage;
     AccessToken = accessToken;
     DefaultLoginAction = defaultLoginAction;
 }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:7,代码来源:LoginResult.cs


示例17: HandleException

        /// <summary>
        /// 处理异常
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool HandleException(Exception exception, out ActionResult result)
        {

            if (exception is ApiResultException)
            {
                var apiRet = ((ApiResultException)exception).Result;
                if (apiRet.code == 401)
                {
                    result = new RedirectResult("http://i.play7th.com/account/login?returnUrl=" + this.HttpContext.Request.Url.ToString());
                    return true;
                }
                if (this.HttpContext.Request.IsAjaxRequest())
                {
                    result = new JsonResult() { Data = (((ApiResultException)exception).Result), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                    return true;
                }
            }
            else if (exception is System.AggregateException)
            {
                exception = exception.InnerException;
                return this.HandleException(exception, out result);
            }
            else if (exception is EfException)
            {
                if (this.HttpContext.Request.IsAjaxRequest())
                {
                    result = new JsonResult() { Data = new ApiResult(7001, exception.Message), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }
            }
            result = null;
            return false;
        }
开发者ID:kissstudio,项目名称:Sunshine.WebApi,代码行数:38,代码来源:MvcHttpContextHandlers.cs


示例18: TempDataActionResult

 public TempDataActionResult(ActionResult actionResult, string message, string classAlert, string classGlyphicon)
 {
     _actionResult = actionResult;
     _message = message;
     _classAlert = classAlert;
     _classGlyphicon = classGlyphicon;
 }
开发者ID:RoganMelo,项目名称:MizeUP,代码行数:7,代码来源:TempDataActionResult.cs


示例19: CreateResult

        public ActionResult CreateResult(ControllerContext controllerContext, ActionResult currentResult)
        {
            var viewResult = currentResult as ViewResult;

            if (viewResult == null)
                return null;

            var viewName = viewResult.ViewName.NullIfEmpty() 
                ?? controllerContext.RequestContext.RouteData.GetRequiredString("action");

            if (viewName.IsNullOrEmpty())
                throw new InvalidOperationException("View name cannot be null.");

            var partialViewName = string.Concat(partialViewPrefix, viewName);

            // check if partial exists, otherwise we'll use the same view
            var partialExists = viewResult.ViewEngineCollection.FindPartialView(controllerContext, partialViewName).View != null;

            var partialViewResult = new PartialViewResult
            {
                ViewData = viewResult.ViewData,
                TempData = viewResult.TempData,
                ViewName = partialExists ? partialViewName : viewName,
                ViewEngineCollection = viewResult.ViewEngineCollection,
            };

            return partialViewResult;
        }
开发者ID:ballrok,项目名称:Fabrik.Common,代码行数:28,代码来源:PartialViewResultFormatter.cs


示例20: RenderActionResultToString

        /// <summary>
        /// Renders an action result to a string. This is done by creating a fake http context
        /// and response objects and have that response send the data to a string builder
        /// instead of the browser.
        /// </summary>
        /// <param name="result">The action result to be rendered to string.</param>
        /// <returns>The data rendered by the given action result.</returns>
        protected string RenderActionResultToString(ActionResult result)
        {
            // Create memory writer.
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            // Create fake http context to render the view.
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(System.Web.HttpContext.Current.Request, fakeResponse);
            var fakeControllerContext = new ControllerContext(
                new HttpContextWrapper(fakeContext),
                this.ControllerContext.RouteData,
                this.ControllerContext.Controller);
            var oldContext = System.Web.HttpContext.Current;
            System.Web.HttpContext.Current = fakeContext;

            // Render the view.
            result.ExecuteResult(fakeControllerContext);

            // Restore data.
            System.Web.HttpContext.Current = oldContext;

            // Flush memory and return output.
            memWriter.Flush();
            return sb.ToString();
        }
开发者ID:ganeshkumar-m,项目名称:PaulSchool,代码行数:33,代码来源:PdfController.cs



注:本文中的System.Web.Mvc.ActionResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.AjaxHelper类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ActionExecutingContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap