1
在我的webapp如何在ServiceStatck Razor頁面+ ServiceStack api中導航?
WEBAPP
\查看
\查看\學校
\視圖\學校\ School.cshtml
\查看\學校\ Schools.cshtml
在Request和Response類:
[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/
在碰到「保存」 BTN返回所需的響應,但在瀏覽器的網址是:
http://test/v1/School
我期待它是:
http://test/School
我怎樣才能獲得url工作對。?根據要求和迴應,它不應該是 http://test/School
。