Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9
This is the forum to discuss the Wrox book Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, Scott Guthrie; ISBN: 978-0-470-38461-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 2nd, 2012, 07:16 AM
Authorized User
Points: 95, Level: 1
Points: 95, Level: 1 Points: 95, Level: 1 Points: 95, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 24
Thanks: 3
Thanked 0 Times in 0 Posts
Default How to pass a model in BeginForm() and use FormMethod.post?

I am trying to develop a widzard that takes user from one page to another, "remembering" what the user has input on first page to the next without saving.

First page: Create.aspx (with 5 fields)
Second page: EstatesUserCreate.aspx (6 fields)

When submit button is hit on the Second page (EstatesUserCreate.aspx) it then saves into the database.

Below are the codes in my controller, Create.aspx and EstatesUserCreate.aspx. It works but when you hover over the submit button of the second page (EstatesUserCreate.aspx), The URL is: ="/Home/EstatesUserCreate?Request_ID=0&RequestBy=.......;I sValid=True" method="post">

It seems to ignore my FormMethod.post in
Code:
<%using (Html.BeginForm("EstatesUserCreate", "Home", Model.Request, FormMethod.Post))
.

If I remove the Model.Request in the BeginForm
Code:
<%using (Html.BeginForm("EstatesUserCreate", "Home", FormMethod.Post))
there is no querystring, which is good, but the values entered in the first page is not being passed.

Please could someone help if I could get rid of the querystring and just have
../Home/EstatesUserCreate/ instead?

In my Controller:
Code:
        // GET: /Request/Create
        public ActionResult Create()
        {
            ViewBag.Mode = "Create";
            var user = (FCWorkRequest.Models.User)Session["CurrentUser"];

            Request request = new Request();

            request.RequestBy = user.Name();
            //request.RequestBy = UsernameHelper.FormatUserName(User.Identity.Name);
            request.RequestBy_eMail = RetriveADInfo.GetADUserInfo()[1];
            request.RequestBy_Department = user.HRProDetails().School_Department_Area;
            request.RequestBy_Location = user.HRProDetails().Workroom;
            request.RequestBy_Phone = user.HRProDetails().Internal_Phone.ToString();

            return View(new RequestFormViewModel(request));
        }


        //POST: /Request/ChooseRequestType
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ChooseRequestType(Request request)
        {
            ViewBag.Mode = "Create";
            var user = (FCWorkRequest.Models.User)Session["CurrentUser"];
            ModelState.Clear();
            if (string.IsNullOrEmpty(request.RequestBy))
                ModelState.AddModelError("request.RequestBy","Request By is required");
            if (string.IsNullOrEmpty(request.RequestBy_eMail))
                ModelState.AddModelError("request.RequestBy_eMail","Request By eMail is required");
            if (request.Request_Department_ID == 0)
                ModelState.AddModelError("request.Request_Department_ID", "Request Department is required");
            if (string.IsNullOrEmpty(request.RequestBy_Location))
                ModelState.AddModelError("request.RequestBy_Location","Request By Location is required");
            if (string.IsNullOrEmpty(request.RequestBy_Phone))
                ModelState.AddModelError("request.RequestBy_Phone","Request By Phone is required");

            if (ModelState.IsValid)
            {
		return View("EstatesUserCreate", new RequestFormViewModel(request));
            }
            else
            {
                return View("Create", new RequestFormViewModel(request));
            }
        }

        //POST: /Request/EstatesUserCreate
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EstatesUserCreate(Request request)
        {
            ModelState.Clear();
            if (request.Request_Category_ID==0)
                ModelState.AddModelError("request.Request_Category_ID", "Category By is required");
            if (request.Date_of_Ticket==null)
                ModelState.AddModelError("request.Date_of_Ticket", "Date of Ticket is required");
            if (string.IsNullOrEmpty(request.Title))
                ModelState.AddModelError("request.Title", "Title is required");

            if (ViewData.ModelState.IsValid)
            {
                    requestRepository.Add(request);
                    requestRepository.Save();
                    return RedirectToAction("Index", new { id = request.Request_ID });
            }
            else
            {
                return View(new RequestFormViewModel(request));
            }
        }

    }
In my Create.aspx

Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<FCWorkRequest.Controllers.RequestFormViewModel>" %>
<%@ Import Namespace="FCWorkRequest.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Create New Request - RequestorDetails
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


<% Html.RenderPartial("AdminMenu"); %>
<h2>Create New Request - RequestorDetails</h2>

<%=Html.ValidationSummary("Please correct the errors and try again") %>

<% using (Html.BeginForm("ChooseRequestType","Home", FormMethod.Post)) { %>
    <div class="modeltype-left">
        <h3>Requestor's Details</h3>
        <fieldset>
            <p>
                <label for="RequestBy">Request By:</label>
                <%= Html.TextBox("RequestBy", Model.Request.RequestBy)%>
                <%=Html.ValidationMessage("Request By", "*")%>        
            </p>  
            <p>
                <label for="RequestBy_eMail">eMail:</label>
                <%= Html.TextBox("RequestBy_eMail", Model.Request.RequestBy_eMail)%>
                <%=Html.ValidationMessage("eMail", "*")%>        
            </p>  
            <p>
                <label for="RequestBy_Department">Department:</label>
                <%= Html.TextBox("RequestBy_Department", Model.Request.RequestBy_Department)%>
                <%=Html.ValidationMessage("Department", "*")%>        
            </p>  
            <p>
                <label for="RequestBy_Location">Location:</label>
                <%= Html.TextBox("RequestBy_Location", Model.Request.RequestBy_Location)%>
                <%=Html.ValidationMessage("Location", "*")%>        
            </p>  
            <p>
                <label for="RequestBy_Phone">Phone:</label>
                <%= Html.TextBox("RequestBy_Phone", Model.Request.RequestBy_Phone)%>
                <%=Html.ValidationMessage("Phone", "*")%>        
            </p>  
        </fieldset>
    </div>

    <div class="modeltype-right">
        <h3>Request Details</h3>
        <fieldset>
            <p>
                <label for="Request_Department_ID">Department:</label>

                    <%=Html.DropDownList("Request_Department_ID",
                                                DepartmentHelper.GetRequestDepartmentsForList(), "--Select One--")%>
                    <%=Html.ValidationMessage("Request for Department", "*")%> 
            </p>
            <p>
                <button type="submit" name="save" value="save" >Next</button>
            </p>
        </fieldset>
    </div>
<% } %>

</asp:Content>
In EstatesUserCreate.aspx:

Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<FCWorkRequest.Controllers.RequestFormViewModel>" %>
<%@ Import Namespace="FCWorkRequest.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Create Estates User Request
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<link type="text/css" href="/Content/jquery-ui-1.8.11.custom.css" rel="stylesheet" />	

<% Html.RenderPartial("AdminMenu"); %>
<h2>Create New Request for Estates - Request Details</h2>

<%=Html.ValidationSummary("Please correct the errors and try again") %>


<%using (Html.BeginForm("EstatesUserCreate", "Home", Model.Request, FormMethod.Post))
  { %>

        <fieldset>
            <p>
                <label for="Request_Category_ID">Category:</label>

                    <%=Html.DropDownList("Request_Category_ID",
                                         CategoryHelper.GetCategoryForList(5), "--Select One--")%>
                    <%=Html.ValidationMessage("Request Category", "*")%> 
            </p>

            <script type="text/javascript" src="/Scripts/jquery-1.5.1.min.js"></script>
            <script type="text/javascript" src="/Scripts/jquery-ui-1.8.11.custom.min.js"></script>
            <script type="text/javascript" src="/Scripts/jquery-ui-timepicker-addon.js"></script>

            <script language="javascript">
                $(document).ready(function () {
                    $('#Date_of_Ticket').datetimepicker();

                    $('#Date_Required').datepicker({ dateFormat: '<%= Html.ConvertDateFormat() %>' });
                }); 
            </script> 
            <p>
                <label for="Date_of_Ticket">Date/Time of Ticket:</label>
                <%= Html.TextBox("Date_of_Ticket", Model.Request.Date_of_Ticket)%>
                <%=Html.ValidationMessage("Date_of_Ticket", "*")%>        
            </p>  
            <p>
                <label for="Date_Required">Date Required:</label>
                <%= Html.TextBox("Date_Required", Model.Request.Date_Required.ToString())%>
            </p>   
            <p>
                <label for="Title">Title:</label>
                <%= Html.TextBox("Title", Model.Request.Title)%>
                <%=Html.ValidationMessage("Title", "*")%>        
            </p>  
            <p>
                <label for="Location_Of_Job">Location of Job:</label>
                <%= Html.TextBox("Location_Of_Job", Model.Request.Location_Of_Job)%>
            </p>  
            <p>
                <label for="Description">Description:</label>
                <%= Html.TextArea("Description", Model.Request.Description, new { @class = "textarea-narrow" })%>
            </p>
            <p>
                <button type="submit" name="save" value="save">Submit</button>
            </p>
        </fieldset>
</form>
<% } %>

</asp:Content>
  #2 (permalink)  
Old July 24th, 2013, 01:18 AM
Authorized User
Points: 42, Level: 1
Points: 42, Level: 1 Points: 42, Level: 1 Points: 42, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: New York
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is pretty much complicated i guess..
__________________
REI Coupon
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Attach Document through Blog post (Create a Post). Ranjan Kumar BOOK: Workflow in SharePoint 2010: Real World Business Workflow Solutions 0 December 2nd, 2011 10:08 AM
Using Html.BeginForm helper method tedr BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 10 May 28th, 2010 09:03 PM
Pass value to second page (create & pass var) ismailc ASP.NET 2.0 Basics 8 April 24th, 2010 07:03 AM
.NET model vs. pre .NET model. raychoudhury BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 January 11th, 2007 05:11 AM
Get Model Property graveman Pro VB 6 0 March 10th, 2004 11:41 AM



All times are GMT -4. The time now is 09:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.