本文整理汇总了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));
}
示例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);
}
示例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());
}
示例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;
}
示例5: Form
public Form(ActionResult result) : base(result)
{
_routeValues = new RouteValueDictionary();
_result = result;
_formMethod = System.Web.Mvc.FormMethod.Post;
_actionTypePassed = ActionTypePassed.HtmlActionResult;
}
示例6: Form
public Form(ActionResult result)
: base(null)
{
this._result = result;
this._formMethod = System.Web.Mvc.FormMethod.Post;
_actionTypePassed = ActionTypePassed.HtmlActionResult;
}
示例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);
}
示例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);
}
示例9: IsFile
public static void IsFile(ActionResult actionResult, string fileName)
{
GenericAssert.InstanceOf<FileStreamResult>(actionResult);
var fileStreamResult = (FileStreamResult)actionResult;
GenericAssert.AreEqual(fileName, fileStreamResult.FileDownloadName);
}
示例10: IsRedirect
public static void IsRedirect(ActionResult actionResult, string targetUrl)
{
GenericAssert.InstanceOf<RedirectResult>(actionResult);
var redirectResult = (RedirectResult)actionResult;
GenericAssert.AreEqual(targetUrl, redirectResult.Url);
}
示例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);
}
示例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);
}
示例13: GoToActivityList
public void GoToActivityList()
{
var controller = CreateActivityController();
var actionResult = controller.Index(); // No assert in the Given & When steps, please
LatestActionResult = actionResult;
}
示例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;
}
示例15: BootstrapActionLink
public BootstrapActionLink(HtmlHelper html, string linkText, ActionResult result)
{
this.html = html;
this._linkText = linkText;
this._result = result;
this._actionTypePassed = ActionTypePassed.HtmlActionResult;
}