當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。