1

私のウェブアプリで

webApp
\Views
\Views\School
\Views\School\School.cshtml
\Views\School\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/

「保存」ボタンを押すと、必要な応答が返されますが、ブラウザーの URL は次のとおりです。

http://test/v1/School

私はそれが次のようになることを期待していました:

http://test/School 

URLを正しく機能させるにはどうすればよいですか? http://test/Schoolリクエストとレスポンスではないはず です。

4

1 に答える 1

1

http://test/school/Getリクエスト DTO と対応する ' ' サービスがルートに実装されていないため、 は何も返しません。

必要なのはリクエスト 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 に答える