아직 기본적인 라우팅, 패턴, 기본 동작, id 스타일이 아닙니다.asp.net mvc ID가 경로에서 가져 오지 못하고 있습니까?
그러나 내 행동에는 이드가 전달되지 않는 것 같습니다. 내 작업 중 하나에 중단 점을 적용하면 id 매개 변수의 값은 null입니다. 뭐라 구요?
Global.asax.cs : TenantsController.cs에
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Tenants", action = "Index", id = "" } // Defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
//RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
}
protected void Application_AuthenticateRequest()
{
if (User != null)
Membership.GetUser(true);
}
}
지수() 조치 : tenantId 매개 변수의
/// <summary>
/// Builds the Index view for Tenants
/// </summary>
/// <param name="tenantId">The id of a Tenant</param>
/// <returns>An ActionResult representing the Index view for Tenants</returns>
public ActionResult Index(int? tenantId)
{
//a single tenant instance, requested by id
//always returns a Tenant, even if its just a blank one
Tenant tenant = _TenantsRepository.GetTenant(tenantId);
//returns a list of TenantSummary
//gets every Tenant in the repository
List<TenantSummary> tenants = _TenantsRepository.TenantSummaries.ToList();
//bilds the ViewData to be returned with the View
CombinedTenantViewModel viewData = new CombinedTenantViewModel(tenant, tenants);
//return index View with ViewData
return View(viewData);
}
값이가는 요리 널 (null)입니다! 아! 바보 같은 부분은 Phil Haack의 Route Debugger를 사용할 때 디버거가 ID를 보는 것을 분명히 알 수 있습니다. 이 얼마나 쓰레기 야?!
당신과 스티븐이 거의 동일하게 대답했으며 두 답이 모두 정확합니다. 그러나 수용 시간은 1 분 전 이었으므로 Mr.Dustpan에게 달려있다. 스티븐의 위대한 설명. – NovaJoe