Finished 'Attribute Routing with Optional Parameter'
parent
0eae1cbf18
commit
4dd245cf1f
|
@ -168,6 +168,8 @@
|
|||
<Content Include="Views\Students\GetStudentByID.cshtml" />
|
||||
<Content Include="Views\Students\GetStudentCourses.cshtml" />
|
||||
<Content Include="Views\Students\GetAllStudents.cshtml" />
|
||||
<Content Include="Views\Home\MVC.cshtml" />
|
||||
<Content Include="Views\Home\WEBAPI.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
|
|
@ -8,22 +8,23 @@ namespace AttributeRoutingDemoInMVC.Controllers
|
|||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public ActionResult Index()
|
||||
// Optional URI Parameter
|
||||
// URL: /MVCTest/
|
||||
// URL: /MVCTest/Pranaya
|
||||
[Route("MVCTest/{studentName ?}")]
|
||||
public ActionResult MVC(string studentName)
|
||||
{
|
||||
ViewBag.Message = "Welcome to ASP.NET MVC!";
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult About()
|
||||
// Optional URI Parameter with default value
|
||||
// URL: /WEBAPITest/
|
||||
// URL: /WEBAPITest/Pranaya
|
||||
[Route("WEBAPITest/{studentName = Pranaya}")]
|
||||
public ActionResult WEBAPI(string studentName)
|
||||
{
|
||||
ViewBag.Message = "Your application description page.";
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Contact()
|
||||
{
|
||||
ViewBag.Message = "Your contact page.";
|
||||
|
||||
ViewBag.Message = "Welcome to ASP.NET WEB API!";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
@{
|
||||
ViewBag.Title = "MVC";
|
||||
}
|
||||
@ViewBag.Message
|
|
@ -0,0 +1,4 @@
|
|||
@{
|
||||
ViewBag.Title = "WEBAPI";
|
||||
}
|
||||
@ViewBag.Message
|
Loading…
Reference in New Issue