2017-12-19 4 views
-2

私はasp.netコアの初心者です。私はのコードを最初に使用して、というアプローチでCreateCustomerAccount.cshtmlというビューページを作成し、CreateCustomerAccountControllerというビューを返すコントローラを追加しました。ただし、コントローラーはHTML /ビューの代わりに空白のページを返しています。私は間違った何かをしましたか?ここで 私のビューページはmvc asp.netに何も表示されていません

はCreateAccount.cshtml

@{ 
ViewData["Title"] = "CreateCustomerAccount"; 
} 

<h2>CreateCustomerAccount</h2> 

<p>User can create account using a form later</p> 

ための私のコードであり、ここで私のCreateCustomerAccountController.csクラス

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Mvc; 

namespace TimeSheetManagementSystem.Controllers 
{ 
public class CreateCustomerAccountController : Controller 
{ 
public IActionResult Index() 
{ 
     return View(); 
    } 

    public IActionResult CreateCustomerAccount() 
    { 
     return View(); 
    } 


    } 
    } 
+0

あなたのビューshou "CreateCustomerAccountController"という名前のフォルダの下にあり、ビュー/ページの名前を "Index.cshtml"または "CreateCustomerAccount.cshtml"にする必要があります。同じ構造ですか? – msoliman

+0

あなたのメソッドの名前は 'Index()'ですので、 'Index.cshtml'という名前を付ける必要があります(' CreateCustomerAccount'はメソッドではなくコントローラの名前です)。代わりに 'return View(" CreateCustomerAccount ");を使用することもできますが、それは意味をなさないでしょう –

+0

ありがとうございました!ビュー名をインデックスに変更し、「Microsoft.AspNetCore.Authorization; をMicrosoft.AspNetCore.Mvc;を使用して追加しました」それは動作します – JApple

答えて

0

コントローラ名とアクションの結果の名前があるべき異なる変更アクションの結果のために私のコードですこのアクチンの名前でビューを再作成してください。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Mvc; 

namespace TimeSheetManagementSystem.Controllers 
{ 
public class CreateCustomerAccountController : Controller 
{ 
public ActionResult Index() 
{ 
    return View(); 
} 

public ActionResult CreateCustomerAccountt() 
{ 
    return View(); 
} 


} 
} 
+0

ありがとうございます!ビュー名をインデックスに変更し、「Microsoft.AspNetCore.Authorization; Microsoft.AspNetCore.Mvcを使用して」を追加しました。それが動作します – JApple

関連する問題