Questions tagged [html.beginform]

Writes an opening

tag to the response. When the user submits the form, the request will be processed by an action method.

The BeginForm method renders a form that will be handled by a controller action method.

You can use this method in a using statement. In that case, the method renders the closing tag at the end of the using block.

For more details click here

177 questions
101
votes
3 answers

@Html.BeginForm Displaying "System.Web.Mvc.Html.MvcForm" on Page

I have a razor view that I added a delete button to inside of an 'if' statement and when the view is rendered in the browser it is displaying "System.Web.Mvc.Html.MvcForm" next to the delete button. How do I get rid of it? Here is the code:
Timothy Green
  • 1,851
  • 5
  • 17
  • 22
59
votes
5 answers

What is the use of @Html.AntiForgeryToken()?

Why we need to use @Html.AntiForgeryToken()? I searched but I didn't get satisfactory answer.
Mhd
  • 771
  • 1
  • 8
  • 15
38
votes
2 answers

How do I add data- attributes to Html.BeginForm

I use the following to create a form to upload images on a mobile site. @using (Html.BeginForm("Form/", "Quote", FormMethod.Post, new { enctype = "multipart/form-data" })) However as it is using jQuery mobile, I have enabled Ajax so that…
Pete
  • 57,112
  • 28
  • 117
  • 166
32
votes
7 answers

Using Html.BeginForm with querystring

My url looks like this: customer/login?ReturnUrl=home In the login view, I have used this pattern of code which works fine. @using(Html.BeginForm()) { ... } This magically generates following html
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
23
votes
3 answers

Html.BeginForm and HTML Attributes w/o specifying Controller and Action

I like the cleanliness of using (Html.BeginForm()) And hate that adding HTML attributes requires specifying the controller, action, and form method. using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id = "inactivate-form"…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
10
votes
2 answers

Why does Html.BeginForm generate empty action?

I have a controller in an area called Admin public class SiteVisitController : Controller { public ViewResult ReadyForCompletion() { ... } public ViewResult CompleteAndExport() { ... } } and a view (ReadyForCompletion.cshtml) that has…
kelloti
  • 8,705
  • 5
  • 46
  • 82
9
votes
1 answer

Create Extension Method to Produce Open & Closing Tags like Html.BeginForm()

I wonder if it's possible to create an extension method which has functionality & behaviour similar to Html.BeginForm(), in that it would generate a complete Html tag, and I could specificy its contents inside <% { & } %> tags. For example, I could…
DaveDev
  • 41,155
  • 72
  • 223
  • 385
9
votes
2 answers

Razor: custom BeginForm()-like Razor disposable block doesn't work in some cases

I have a custom implementation of a block that works much like Html.BeginForm(). The implementation is basically as follows: public class MyBlock : IDisposable { private readonly HtmlHelper _html; public MyBlock(HtmlHelper hml) { …
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
7
votes
2 answers

rolling my own @Html.BeginfBrm()

I am writing a custom validation set that will display all missing elements on a div. I'd like to be able to use a custom @Html.BeginForm() method that will write out that div but I'm really not sure where to even begin as this nut is a little…
Christopher Johnson
  • 2,629
  • 7
  • 39
  • 70
7
votes
3 answers

Why does BeginForm("Foo") add a "Length" key to the query string?

I am not new to MVC so I am a bit baffled at why I can't change the URL of my POST when I click the submit button. I have this simple view called PandoraRemovalTool.cshtml @{ ViewBag.Title = "PandoraRemovalTool"; } @using…
nick gowdy
  • 6,191
  • 25
  • 88
  • 157
6
votes
2 answers

Rewriting Html.BeginForm() in MVC 3.0 and keeping unobtrusive javascript

This is going to seem like a bit of a silly endeavor, but it's something I want to learn nonetheless. Right now, in ASP.NET MVC 3.0, you need to use the syntax @using (Html.BeginForm()) { and then later, the } to close a form block to get the fancy…
Ciel
  • 17,312
  • 21
  • 104
  • 199
5
votes
2 answers

Passing a List as @Html.Hidden and the list is being deleted

I am having an issue sending through a list from a form to a controller to work with and edit. It just destroys the list and passes through just one empty string. I need the list to maintain so that i can add to it in the controller. The view looks…
rubidge96
  • 109
  • 2
  • 12
5
votes
1 answer

Html.BeginForm multipart/form-data File Upload form-group validation

I have a cshtml file to Upload files to the server. @using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() @Html.ValidationSummary();
5
votes
3 answers

Html.BeginForm() with only form Id is not generating correct action url

I only want to add the formId in the beginForm() If i try using Html.BeginForm(null, null, FormMethod.Post, new {@id="Id"}) then the Html generated is i don't know how…
Amit
  • 63
  • 1
  • 1
  • 10
4
votes
2 answers

Html.BeginForm call the right Action in Controller

There are a lot of topics related to this question but I still did't figured out what I'm doing wrong. I have a database where I manage access of different users to folders. On my View the User can select Employees which should have access to…
Paul S
  • 89
  • 12
1
2 3
11 12