ASP.NET/MVC 3

ASP.NET MVC 3 View 추가하기

littlemk 2018. 8. 23. 15:13

ASP.NET MVC 3 View 추가하기

Visual studio 2010 express 버전



  1. Test0821.Controllers 코드 수정
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Test0821.Controllers
{
    public class Test0821Controller : Controller
    {
        //
        // GET: /Home/
       // public ActionResult Index()
        //{
            //return View();
        //}
        // 홈페이지상에서 보여질 문구
        //public string Index()
        //{
            //return "안녕하세요?a~ HomeController 실?C행a했??습?A니?I다?U.";
        //}
        // View 추??가???하I기?a
        public ViewResult Index()
        {
            return View();
        }
    }
}


  1. View 추가하기
  • return View(); -> 우 클릭 -> Add View클릭





  1. Index.cshtml(View 파일) 추가된 모습


  1. Index.cshtml 코드 변경
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
       <title></title>
</head>
<body>
       <div>
              안?E녕?c하I세???요?a! Index.cshtml 뷰?a 페?a이I지o입O니?I다?U.
       </div>
</body>
</html>


  1. 디버깅 결과



  1. Test0821.Controllers 파일 코드 변경
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Test0821.Controllers
{
    public class Test0821Controller : Controller
    {
        //
        // GET: /Home/
       // public ActionResult Index()
        //{
            //return View();
        //}
        // 홈??페?a이I지o상?o에???서??? 보???여???질u 문???구???
        //public string Index()
        //{
            //return "안?E녕?c하I세???요?a~ HomeController 실?C행a했??습?A니?I다?U.";
        //}
        // View 추??가???하I기?a
        public ViewResult Index()
        {
            string str_Message = "동???적u 출a력?A하I는?A 부?I분???입O니?I다?U.";
            ViewBag.Hello = str_Message;
            return View();
        }
    }
}




  1. Index.cshtml 코드 변경
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
       <title></title>
</head>
<body>
       <div>
              안?E녕?c하I세???요?a! Index.cshtml 뷰?a 페?a이I지o입O니?I다?U.
       </div>
       @ViewBag.Hello
</body>
</html>




  1. 디버깅 결과