2008-11-07 6 views

답변

8

, 당신은 URL을 http://localhost:50034/Admin/Delete/가 예외를 생성하는 것을 의미합니까?

과 같이, 같은 널 (NULL) id 매개 변수를 설정하십시오 :

public class MyController : Controller 
{ 
    public void Delete(int? id) 
    { 
    if (!id.HasValue) 
    { 
     return RedirectToAction("Index", "Home"); 
    } 

    /// 
    } 
} 
3
public ActionResult Details(int? Id) 
{ 
    if (Id == null) 
      return RedirectToAction("Index"); 
    return View(); 
} 
1

기본 라우팅 규칙을 사용하고 있다고 가정하면 다음 널 (NULL)의 INT와 삭제 방법을 만들

routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
    ); 

을 (INT ?)는

과 유사합니다.
public ActionResult Delete(int? id) 
{ 
    if (id.HasValue) 
    { 
     // do your normal stuff 
     // to delete 
     return View("afterDeleteView"); 
    } 
    else 
    { 
     // no id value passed 
     return View("noParameterView"); 
    } 

}

관련 문제