 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

April 16th, 2010, 03:38 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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(); %>

|
|

April 16th, 2010, 03:45 PM
|
 |
Wrox Author
|
|
Join Date: Aug 2008
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
|
|
Your syntax for the second isn't valid.
|
|

April 16th, 2010, 04:06 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
syntac
can you explin that comment, is there a better way to do it or am I unable to use this helper method
|
|

April 16th, 2010, 04:07 PM
|
 |
Wrox Author
|
|
Join Date: Aug 2008
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
|
|
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">); %>
|
|

April 16th, 2010, 04:33 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
How
OK is there a way to use the helper method to do this, and what would the syntac be? 
|
|

April 16th, 2010, 05:08 PM
|
 |
Wrox Author
|
|
Join Date: Aug 2008
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
|
|
|
|

April 16th, 2010, 05:36 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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" } )); %>"

|
|

April 17th, 2010, 09:38 AM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Html.BeginForm()
bas ed 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
|
|

April 19th, 2010, 02:20 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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.
|
|

April 19th, 2010, 02:43 PM
|
 |
Wrox Author
|
|
Join Date: Aug 2008
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
|
|
Quote:
Originally Posted by tedr
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.
|
|
The Following User Says Thank You to nberardi For This Useful Post:
|
|
|
 |