html.beginform

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

眉间皱痕 提交于 2019-11-30 07:09:14
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 have a view like: <% using(Html.BeginDiv("divId")) %> <% { %> <!-- Form content goes here --> <% } %> This capability would be very useful in the context of the functionality I'm trying to produce with the example in this question This would give me the ability to create containers for the types that I'll be <% var myType = new MyType(123, 234); %>

Pass SelectedValue of DropDownList in Html.BeginForm() in ASP.NEt MVC 3

吃可爱长大的小学妹 提交于 2019-11-29 05:19:58
This is my View Code: @using(Html.BeginForm(new { SelectedId = /*SelectedValue of DropDown*/ })) { <fieldset> <dl> <dt> @Html.Label(Model.Category) </dt> <dd> @Html.DropDownListFor(model => Model.Category, CategoryList) </dd> </dl> </fieldset> <input type="submit" value="Search" /> } As code shown I need to pass the dropdown selected value to the action in BeginForm() Html helper. What is your suggestion? Darin Dimitrov The selected value will be passed when the form is submitted because the dropdown list is represented by a <select> element. You just need to adapt your view model so that it

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 19:49:54
问题 Why we need to use @Html.AntiForgeryToken() ? I searched but I didn't get satisfactory answer. 回答1: This is a security feature to help protect your application against cross-site request forgery. Example: Lets assume you have a register functionality in your web app. You have an AccountController (somename.com/account/register) where you expect people to submit their info. Normally before someone posts the registration information needs to visit the actual (somename.com/account/register) than

Pass SelectedValue of DropDownList in Html.BeginForm() in ASP.NEt MVC 3

≯℡__Kan透↙ 提交于 2019-11-27 22:43:15
问题 This is my View Code: @using(Html.BeginForm(new { SelectedId = /*SelectedValue of DropDown*/ })) { <fieldset> <dl> <dt> @Html.Label(Model.Category) </dt> <dd> @Html.DropDownListFor(model => Model.Category, CategoryList) </dd> </dl> </fieldset> <input type="submit" value="Search" /> } As code shown I need to pass the dropdown selected value to the action in BeginForm() Html helper. What is your suggestion? 回答1: The selected value will be passed when the form is submitted because the dropdown

@Html.BeginForm Displaying “System.Web.Mvc.Html.MvcForm” on Page

一曲冷凌霜 提交于 2019-11-27 13:50:28
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: <div id="deletestatusupdate"> @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase)) { @Html.BeginForm("deleteupdate", "home") @Html.Hidden("returnUrl", Request.Url.ToString()) <button name="id" value="@update.StatusUpdateId">Delete</button> } </div> Here is how it shows up in the rendered Razor View: System.Web.Mvc.Html