开发者

passing values from view to Controller N then to other View

Customer:
<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>

Now i got to pass the <%:item.Customer %> through the %: Html.ActionLink("Create New", "Create", "Profile", null, null)%> and that should be displayed in the Create view here is the Controller n i will give the Create view too

Controller: 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);
    }

the Create View <%if(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>


What exactly is your issue?

On the side point, you should be using Model Binding to pass a person object to the CreateView action method rather than passing each property separately. It will reduce a lot of your code. Search Model Binding for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜