은과 같이 주어진 컨트롤러 에서 액션 이름을 열거를 만드는 것입니다 :
public class HomeController : Controller
{
public enum Actions
{
Index,
About,
Contact,
Hosting,
Hartware
}
을 난에 확장 방법을 만들고 싶습니다 원래 클래스와 동일한 네임 스페이스를 사용 연장, 내 페이지의 상단에있는이 경우 "HomeController"에 도착하여 추가이 경우에 나는 System.Web.Mvc를 사용하는 것이 내 면도기 ViewPage에
namespace System.Web.Mvc
{
public static class MvcExtentions
{
/// <summary>
/// Generates a fully qualified URL to an action method by using the specified action Name.
/// </summary>
/// <param name="sender">used for the generate the logic</param>
/// <param name="actionName">an enum that will be used to generate the name from</param>
/// <returns>a fully qualified url to the action in the current controller</returns>
public static string Action(this UrlHelper sender, Enum actionName)
{
return sender.Action(actionName.ToString());
}
}
}
다음 클래스를 생성 여기서 ByteStream은 내 proj의 이름입니다. 요법
@using ByteStream.Web.Controllers
@{
ViewData["Title"] = "Home Page";
}
링크를 생성하려면 그때 사용
<a class="btn btn-default btn-default" ref="@Url.Action(HomeController.Actions.Hosting))">
Learn More
</a>