Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950
This is the forum to discuss the Wrox book ASP.NET MVC Website Programming Problem Design Solution by Nicholas Berardi, Al Katawazi, and Marco Bellinaso; ISBN: 9780470410950
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 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 April 16th, 2010, 04:38 PM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default Using Html.BeginForm helper method

I like using the Html.BeginForm and Html.EndFrom helper functions,

And was wondering why in the book you don't, is there a reason for this or a matter of preference.

<formmethod="post"action="<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article") %>"class="category-create">

Couldn't this of been done like this?

<% Html.BeginForm(method="post"action="<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article") %>"class="category-create">); %>

<% Html.EndForm(); %>

  #2 (permalink)  
Old April 16th, 2010, 04:45 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Your syntax for the second isn't valid.
__________________
Check out my blog at: http://www.coderjournal.com
  #3 (permalink)  
Old April 16th, 2010, 05:06 PM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Question syntac

can you explin that comment, is there a better way to do it or am I unable to use this helper method
  #4 (permalink)  
Old April 16th, 2010, 05:07 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Your syntax is wrong. There is no way that this will compile and execute:

<% Html.BeginForm(method="post"action="<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article") %>"class="category-create">); %>
__________________
Check out my blog at: http://www.coderjournal.com
  #5 (permalink)  
Old April 16th, 2010, 05:33 PM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default How

OK is there a way to use the helper method to do this, and what would the syntac be?
  #6 (permalink)  
Old April 16th, 2010, 06:08 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

You can find all the parameters for BeginForm here:

http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
__________________
Check out my blog at: http://www.coderjournal.com
  #7 (permalink)  
Old April 16th, 2010, 06:36 PM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default What if

OK what if I do this

<% Html.BeginForm("<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article" %>", FormMethod.Post, new { class = "category-create" } )); %>"


  #8 (permalink)  
Old April 17th, 2010, 10:38 AM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default Html.BeginForm()

based off link by Jacques, this is what I came up with, but still not sure if URL part will get put into the action=

string for the action part =
<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article" %>"

the Post method =
FormMethod.Post

the Id which I changed to a class =
new { class = "category-create" }
the last one I guess would be anobject


<% Html.BeginForm(<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article" %>", FormMethod.Post, new { class = "category-create" } )); %>"


On http://forums.asp.net/t/1361569.aspx, someone said

You can specify addition attributes if you use the overloads that take htmlAttributes as a parameter. For example,

<% using (Html.BeginForm("foo", "bar", FormMethod.Post, new { id = "myID" }))
{ %>
<%} %> will result in the following HTML:
<form action="/bar/foo" id="myID" method="post"></form>
Not sure whether I understand the first part correctly. Do you only want to generate the opening <form> tag?
Jacques
  #9 (permalink)  
Old April 19th, 2010, 03:20 PM
Authorized User
 
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Default Html.BeginForm Helper

This what I come up with to actually get the code to get a clean compile

<% Html.BeginForm(this.ViewContext.RouteData.Values["action"] asstring, "Article", FormMethod.Post, new { @class = "category-create" } ); %>


Will this do what was expected in the form action in the book.
  #10 (permalink)  
Old April 19th, 2010, 03:43 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Quote:
Originally Posted by tedr View Post
Will this do what was expected in the form action in the book.
Remember there is no magic with the web, it is all HTTP with GET and POST most of the time, if what the resulting HTML from the helper method generates is close or exactly like the HTML shown in the book then the answer is yes, if it isn't then you may have the tweak some.

By the way I am purposely avoiding the question you want answered, because it is very easy to verify that the HTML is the same. Once you dive in to the HTML and start looking around and taking some of the magic out of what the ASPX page shows and what the resulting HTML is it will help you become a better programmer. Right now I feel like you are using this forum as a crutch, and you don't have to, because if you were smart enough to want to learn something new like MVC, you are smart enough to understand what you see in an HTML markup.
__________________
Check out my blog at: http://www.coderjournal.com
The Following User Says Thank You to nberardi For This Useful Post:
tedr (April 19th, 2010)
 


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
form helper blackhorse66 BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 0 June 24th, 2009 03:01 PM
Need of Helper and Global classes rajanikrishna BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 December 22nd, 2008 06:14 PM
help with Muenchian method grouping and html table mickhughes XSLT 3 May 1st, 2008 07:24 AM
onChange method of <select> in Html not working pushpa Classic ASP Databases 4 January 23rd, 2007 11:20 AM
'helper' function? jtyson ASP.NET 1.0 and 1.1 Basics 1 June 29th, 2004 09:12 AM



All times are GMT -4. The time now is 01:16 AM.


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