Finished 'Route Prefix in Attribute Routing'
This commit is contained in:
parent
a4d2fda2a9
commit
e553d28b48
@ -126,6 +126,7 @@
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\Student.cs" />
|
||||
<Compile Include="Models\Teacher.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -170,6 +171,7 @@
|
||||
<Content Include="Views\Students\GetAllStudents.cshtml" />
|
||||
<Content Include="Views\Home\MVC.cshtml" />
|
||||
<Content Include="Views\Home\WEBAPI.cshtml" />
|
||||
<Content Include="Views\Students\GetTeachers.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
@ -54,5 +54,19 @@ namespace AttributeRoutingDemoInMVC.Controllers
|
||||
ViewBag.CourseList = CourseList;
|
||||
return View();
|
||||
}
|
||||
|
||||
[Route("~/tech/teachers")]
|
||||
// This will be translated to /tech/teachers
|
||||
public ActionResult GetTeachers()
|
||||
{
|
||||
List<Teacher> teachers = new List<Teacher>()
|
||||
{
|
||||
new Teacher() {Id = 1, Name = "James"},
|
||||
new Teacher() {Id = 2, Name = "Patrik"},
|
||||
new Teacher() {Id = 3, Name = "Smith"}
|
||||
};
|
||||
return View(teachers);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
AttributeRoutingDemoInMVC/Models/Teacher.cs
Normal file
13
AttributeRoutingDemoInMVC/Models/Teacher.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace AttributeRoutingDemoInMVC.Models
|
||||
{
|
||||
public class Teacher
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
28
AttributeRoutingDemoInMVC/Views/Students/GetTeachers.cshtml
Normal file
28
AttributeRoutingDemoInMVC/Views/Students/GetTeachers.cshtml
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
@model IEnumerable<AttributeRoutingDemoInMVC.Models.Teacher>
|
||||
@{
|
||||
ViewBag.Title = "Get Teachers";
|
||||
}
|
||||
|
||||
<h2>GetTachers</h2>
|
||||
<teacher class="table">
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Id)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Name)
|
||||
</th>
|
||||
</tr>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</teacher>
|
Loading…
x
Reference in New Issue
Block a user