2010-11-19 28 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傳遞值然後其他View

控制器: public Actio nResult Create() {0}返回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); 
    } 

創建視圖 <%如果(TempData的[ 「UserCreationMsg」]!= NULL)%> <%{%> <%:TempData的[ 「UserCreationMsg」]的ToString()% > <%}%>

<% 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 2010-11-19 02:02:12

回答

1

究竟什麼是您的問題?

從側面看,您應該使用模型綁定將人物對象傳遞給CreateView操作方法,而不是分別傳遞每個屬性。它會減少很多你的代碼。搜索模型綁定了解更多詳情。

+0

只是想讓CustomerNo顯示在創建頁面上 – CoderUnknown 2010-11-19 17:46:25

+0

爲什麼不簡單地將CustomerNo放在ViewData中並在視圖中使用它。就像你使用TempData for Error消息一樣。沒有? – neebz 2010-11-19 22:19:08

相關問題