2010-11-19 3 views
0
고객 :
<p></p> 
<p></p> 
<div> <% foreach (var item in Model) 
     { %> 
     You are viewing Users of Customer: <%:item.Customer %> 
     <%break; %> 
     <%} %></div> 
    <p></p> 
    <% Html.RenderPartial("EditUsers", Model); %> 

<p> 
    <%: Html.ActionLink("Create New", "Create", "Profile", null, null)%> 
</p> 

이제 < % : item.Customer %>를 % : Html.ActionLink ("Create New", "Create", "Profile" null, null) %> 그리고 그보기에 표시되어야합니다. 컨트롤러는 ni도 만들기보기를 제공합니다.뷰에서 컨트롤러 N으로 값을 전달한 다음 다른 뷰로 값 전달

컨트롤러 : public ActionResult Create() { return View(); }

 [HttpPost] 
    public ActionResult Create(string UserName, string Password, string FirstName, string LastName, 
     string MiddleInitial, string Email,string Telephone, bool IsAdmin, bool IsSubAdmin) 
    { 
     UserDAL userDALObject = new UserDAL(); 
     tblUser newUser = new tblUser(); 

     newUser.Customer = customerNumber; 
     newUser.UserName = UserName; 
     newUser.Password = Password; 
     newUser.FirstName = FirstName; 
     newUser.LastName = LastName; 
     newUser.MiddleInitial = MiddleInitial; 
     newUser.Email = Email; 
     newUser.Telephone = Telephone; 

     newUser.IsAdmin = IsAdmin; 
     newUser.IsSubAdmin = IsSubAdmin; 

     userDALObject.AddUserDetails(newUser); 
     TempData["UserCreationMsg"] = string.Format("User named :{0}, is created",UserName); 
     return View(); 
    } 
    public ActionResult EditUser(string id) 
    { 
     UserDAL userDALObject = new UserDAL(); 
     tblUser userDetails = userDALObject.GetUser(Int32.Parse(id)); 
     TempData["EditUserId"] = id; 
     return View(userDetails); 
    } 

만들기보기 < % if (TempData [ "UserCreationMsg"]! = null) %> < % {x> < % : TempData [ "UserCreationMsg"]. > < %} %>

<% using (Html.BeginForm()) {%> 
    <%: Html.ValidationSummary(true) %> 

    <fieldset>   


     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.UserName) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("UserName") %> 
      <%: Html.ValidationMessageFor(model => model.UserName) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Password) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.Password("Password") %> 
      <%: Html.ValidationMessageFor(model => model.Password) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.FirstName) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("FirstName") %> 
      <%: Html.ValidationMessageFor(model => model.FirstName) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.LastName) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("LastName") %> 
      <%: Html.ValidationMessageFor(model => model.LastName) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.MiddleInitial) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("MiddleInitial") %> 
      <%: Html.ValidationMessageFor(model => model.MiddleInitial) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Email) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("Email") %> 
      <%: Html.ValidationMessageFor(model => model.Email) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Telephone) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBox("Telephone") %> 
      <%: Html.ValidationMessageFor(model => model.Telephone) %> 
     </div>   


     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.IsAdmin) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.CheckBox("IsAdmin") %> 
      <%: Html.ValidationMessageFor(model => model.IsAdmin) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.IsSubAdmin) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.CheckBox("IsSubAdmin") %> 
      <%: Html.ValidationMessageFor(model => model.IsSubAdmin) %> 
     </div> 

     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
+1

문제는 무엇입니까? – jfar

답변

1

?

측면에서, 각 특성을 별도로 전달하지 않고 모델 오브젝트를 사용하여 개인 오브젝트를 CreateView 조치 메소드로 전달해야합니다. 그것은 많은 코드를 줄일 것입니다. 자세한 내용은 모델 바인딩 검색을 참조하십시오.

+0

단지 CreateNode를 생성 페이지 – CoderUnknown

+0

에 표시하려면 CustomerNo를 ViewData에 넣고 뷰에 사용하는 것이 어떻습니까? 마치 TempData for Error 메시지를 사용하는 것과 같습니다. 아니? – neebz

관련 문제