using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcMusicStore.Controllers { public class StoreController : Controller { // // GET: /Store/ public string Index() { return "MvcMusicsStore.Controllers.StoreController.Index"; } } }
解决方法
没有任何硬编码?有可能吗
public string Index() { return GetType().FullName + GetMemberName(); } static string GetMemberName([CallerMemberName] string memberName = "") { return memberName; }
或者也许更漂亮:
public string Index() { return GetMemberName(this); } static string GetMemberName( object caller,[CallerMemberName] string memberName = "") { return caller.GetType().FullName + "." + memberName; }