FormCollection


--------------------------------------------------------------------

[HttpPost]

public ActionResult Create()

{

if(ModelState.IsValid)

{

Employee employee =new

UpdateModel(employee);



EmployeeBusinessLayer employeeBusinessLayer

mployeeBusinessLayer.AddEmployee(employee);


return RedirectToAction("Index");



[HttpPost]

[ActionName("Create")] -> 이렇게 선언해놓으면 Create 하면 아래 함수로 호출됨

public ActionResult Create_Post()

{

if(ModelState.IsValid)

{

Employee employee =new

UpdateModel(employee); //아래 설명



EmployeeBusinessLayer employeeBusinessLayer

mployeeBusinessLayer.AddEmployee(employee);


return RedirectToAction("Index");



[HttpPost]

[ActionName("Create")] -> 이렇게 선언해놓으면 Create 하면 아래 함수로 호출됨

public ActionResult Create_Get()

{

return View();

}




UpdateModel 함수

inspects all the HttpRequest inputs such as posted Form data, QueryString, Cookies, Server Variables and populate the employee object.


--------------------------------------------------------------------

UpdateModel and TryUpdateModel 차이점






--------------------------------------------------------------------

Nuget Package Manager에서

Entity Framework 설치

그리고 소스에서

using System.ComponentsModel.DataAnnotations; 추가


생성자에서 각 속성값 위에

[Required] 추가해줌


그리고

컨트롤러 public ActionResult Create_Post() 함수에서

Employee employee = new Employee();

TryUpdateModel(employee); //함수로 변경 


결과 입력Form 양식에서 

validation check가 됨


그러나 결론은 

UpdateModel(), TryUpdateModel() 함수 둘다 mandatory 아님

그래도 명시적으로 해주는 이유는

If you want to limit on what can be bound,

expllicitly invoking model binding can be very useful.


--------------------------------------------------------------------

Edit


[HttpGet]

public ActionResult Edit(int id)


new employeeBusinessLayer

employee = employeeBusinessLayer.Employees.Single(emp => emp.ID == id);

return View(employee);

그리고 우측키 눌러서 Add View

Model Class 선택

그리고 제공해주는 템플릿 선택 Scaffold template "Edit" 선택

--------------------------------------------------------------------

[HttpPost]

public ActionResult Edit함수 추가

비지니스레이어에 mod함수 추가



--------------------------------------------------------------------

기존 Html Helper

@Html.EditorFor(model => model.Name)

@Html.ValidationMessageFor(model => model.Name)

-> 태그로 변경되면 input 박스


UnEditorble로 변경

@Html.DisplayFor(model => model.Name)

@Html.ValidationMessageFor(model => model.Name)

-> 그냥 plain text로 render됨


수정누르면 field is required로 나옴

히든필드에 저장해놓으면 됨

@Html.DisplayFor(model => model.Name)

@Html.HiddenFor(model => model.Name)

@Html.ValidationMessageFor(model => model.Name)


--------------------------------------------------------------------

피들러 이용해서 (일종의 해킹)

POST 요청 보내어 데이터 수정이 그낭함

피들러 왼쪽 리스트에서 해당 요청건을 오른쪽 영역 Composer로 드래그 드랍

그리고 아래쪽 POST URL에서 수정하고 싶은 값을 고쳐서 Excute하면

실제로 서버로 POST 요청이 들어감 



--------------------------------------------------------------------




--------------------------------------------------------------------




+ Recent posts