当前位置: 首页>>代码示例>>C#>>正文


C# Mvc.ActionResult类代码示例

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


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


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