在我的网络应用程序中
webApp
\Views
\Views\School
\Views\School\School.cshtml
\Views\School\Schools.cshtml
在请求和响应类中:
[Route("/v1/school", Verbs = "POST")]
[DefaultView("School")]
public class SchoolAddRequest : School, IReturn<SchoolResponse>
{
}
public class SchoolResponse
{
public School School { get; set; }
public SchoolResponse()
{
ResponseStatus = new ResponseStatus();
Schools = new List<School>();
}
public List<School> Schools { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
在 SchoolService.cs 中:
[DefaultView("School")]
public class SchoolService: Service
{
public SchoolResponse Post(SchoolAddRequest request)
{
var sch = new School {Id = "10"};
return new SchoolResponse {School = sch, ResponseStatus = new ResponseStatus()};
}
}
在 school.cshtml 中:
@inherits ViewPage<Test.Core.Services.SchoolResponse>
@{
Layout = "_Layout";
}
<form action="/v1/School" method="POST">
@Html.Label("Name: ") @Html.TextBox("Name")
@Html.Label("Address: ") @Html.TextBox("Address")
<button type="submit">Save</button>
</form>
@if (@Model.School != null)
{
@Html.Label("ID: ") @Model.School.Id
}
在浏览器上:
这应该可以工作,但事实并非如此,我得到一个空白页面
http://test/school/
这有效:
http://test/views/school/
在点击“保存”按钮时,返回所需的响应,但浏览器上的 url 是:
http://test/v1/School
我期待它是:
http://test/School
我怎样才能让网址正常工作。?不应该是
http://test/School
请求和响应。