본문 바로가기
728x90
반응형

ASP.NET MVC22

ASP.NET MVC] Ajax Submit - .post() Ajax를 이용하여, form data submit Add Comment를 클릭 시, text area가 포함된 form이 submit 되어 Comments list를 보여주도록 처리해보자. Index.cshtml @model IEnumerable @{ ViewBag.Title = "Home Page"; } @section head { } Comments @foreach (var comment in Model) { @comment } @Html.TextArea("Comment", new { rows = 5, cols = 50 }) AjaxDemo.js $(document).ready(function () { // DOM load 시 실행됨 $('#commentForm').submit(function (e.. 2022. 7. 12.
ASP.NET MVC] Ajax Request - .load() jQuery를 이용하여, Ajax request 실행 jQuery는 Ajax와 관련된 메소드를 제공한다. $.ajax() 비동기식 Ajax를 이용하여 HTTP 요청을 전송함. $.get() 전달받은 주소로 GET 방식의 HTTP 요청을 전송함. $.post() 전달받은 주소로 POST 방식의 HTTP 요청을 전송함. $.getScript() 웹 페이지에 스크립트를 추가함. $.getJSON() 전달받은 주소로 GET 방식의 HTTP 요청을 전송하여, 응답으로 JSON 파일을 전송받음. .load() 서버에서 데이터를 읽은 후, 읽어 들인 HTML 코드를 선택한 요소에 배치함. index.html 에서 Show the About 링크 클릭 시, index page로 About content를 load하는 .. 2022. 7. 12.
ASP.NET MVC] View Model View Model이란? view에서 사용하기 위해 디자인된 model이다. 온라인 상점 예시 온라인 상점 application에는 Customer, Order, Product와 같은 class가 포함된다. public class Customer { public int Number { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public bool Active { get; set; } public ServiceLevel ServiceLevel { get; set; } public IEnumerable Orders { get; set; } } public enum ServiceLevel { St.. 2022. 7. 11.
ASP.NET MVC] ActionResult, Custom ActionResult ActionResult action method는 ActionResult instance를 반환한다. public class HomeController : Controller { public ActionResult Index() { return View(); } } ActionResult는 abstract class이며, 모든 action result의 base class이다. ExecuteResult라는 abstract method가 있으며, 파생 class에서 구현한다. ActionResult는 많은 파생 class를 가지고 있으며, 다음 3가지로 유형으로 나눌 수 있다. content-returning, redirection, status results 예를들면 ContentResult Class는.. 2022. 7. 11.
ASP.NET MVC] Controller, Actions, IController, ControllerBase Controller 설명 controller는 ASP.NET MVC의 core component이며, model의 data를 view로 옮겨주는 접착제 같은 역할을 한다. controller는 Controller Class를 상속받으며, action을 정의하는 public 함수를 포함한다. 하지만 controller가 꼭 Controller Class를 상속받아야 하는 것은 아니다. IController interface를 구현하는 것으로도 web request를 처리할 수 있다. public class HomeController : Controller { public ActionResult Index() { return View(); } } Controller actions action method는 .. 2022. 7. 11.
ASP.NET MVC] Sub Select Option 동적 변경 cshtml 소속 경기도지사 강원도지사 담당자명 branch select가 변경될 때, 소속 담당자리스트를 가져와서 option을 동적으로 생성해주도록 하자. $(document).ready(function () { $("#branch").change(function () { fn_setBranchEmpList($(this).val(),'담당자명'); }); }); function fn_setBranchEmpList(selected_branch, selected_emp) { var jsonData = JSON.stringify({ branch: selected_branch }); $.ajax({ type: 'POST', url: "/Member/GetEmpListByBranchName", contentT.. 2022. 5. 27.
728x90
반응형