1

在我的网络应用程序中

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请求和响应。

4

1 回答 1

1

http://test/school/没有返回任何内容,因为您没有请求 DTO 和Get为该路由实现的相应“”服务。

你需要的是一个请求 DTO:

[Route("/school", Verbs = "GET")]  
public class GetSchool : IReturn<SchoolResponse>
{

}

和服务...

public SchoolResponse Get(GetSchool request)
    {
        var sch = new School {Id = "10"};
        return new SchoolResponse {School = sch, ResponseStatus = new ResponseStatus()};
    }

当您点击“保存”时,将通过路由“ v1/school ”向服务器发出“POST”请求,因为您指定的表单标签具有:

<form action="/v1/School" method="POST">

希望这可以帮助。

于 2013-08-05T15:19:06.477 回答