Action Results Type ViewResult
Helper Method
View()
PartialViewResult
PartialView()
ContentResult
Content()
RedirectResult
Redirect()
RedirectToRouteResult
RedirectToAction()
JsonResult
Json()
FileResult
File()
HttpNotFoundResult
HttpNotFound()
EmptyResult
Action Parameters Sources • Embedded in the URL: /movies/edit/1 • In the query string: /movies/edit?id=1 • In the form data
1
By: Mosh Hamedani
By: Mosh Hamedani
Convention-based Routes !"#$%&'()*+"#$%, .("/0%&12+%3%)&%4)$%56 .7"/0%&8!%3%)&%98:2%)!;8:7"<$=;56 <%> : ?"<$!"33%! @ .("/0%&56 )?$0"< @ .("/0%&+%3%)&%124)$%5 ;6 <%> : 2%)! @ A.B9:C;6 7"<$= @ A.B9:D;5 ; 0&E)/"!0$% @ F)3&%G ;
Attribute Routes H+"#$%,.7"/0%&8!%3%)&%98:2%)!;8:7"<$=;5I *#J30? K?$0"<+%$ ("/0%&12+%3%)&%4)$%,0<$ 2%)!6 0<$ 7"<$=I : ; To apply a constraint use a colon:
7"<$=L!%M%N,BB9:D;IL!)
2
By: Mosh Hamedani
Passing Data to Views Avoid using ViewData and ViewBag because they are fragile. Plus, you have to do extra casting, which makes your code ugly. Pass a model (or a view model) directly to a view:
!%$#!< P0%>,7"/0%IG
Razor Views A0F ,QI : 88 RS ?"9% "! TU(V ;
AF"!%)?= ,QI : ;
Render a class (or any attributes) conditionally:
A: /)! ?3)&&W)7% @ ("9%3'R#&$"7%!&'R"#<$ X Y Z .*"*#3)!5 L <#33G ; [=D ?3)
[email protected]?3)&&W)7%5XQ[8=DX
3
Partial Views To render:
AT$73'\)!$0)3,.]W)/1)!5I
4
By: Mosh Hamedani