html-helper

Using an MVC HtmlHelper from a WebForm

余生长醉 提交于 2019-11-27 07:28:07
I'm in the process of adding some UI functionality to a hybrid WebForms/MVC site. In this case, I'm adding some AJAX UI features to a WebForms page (via jQuery), and the data is coming from an MVC JsonResult. Everything is working 100%, with one exception: I would like to implement the XSRF protection of AntiForgeryToken. I have used it in combination with the ValidateAntiForgeryToken attribute on my pure MVC applications, but would like to know how to implement the Html.AntiForgeryToken() method in WebForms. Here's an example using a UrlHelper . I'm having some trouble getting ViewContext /

custom htmlhelper with validation support

本小妞迷上赌 提交于 2019-11-27 07:25:00
问题 I'm rockin my own custom HtmlHelper to enable AutoComplete support on a Select List. This is working alright, except I need to be able to support the DataAnnotations in my ViewModel. Here's my current (working) HtmlHelper (sans validation) <Extension()> Public Function AutoCompleteDropDownList(ByVal helper As HtmlHelper, name As String, autoCompleteSelectListItem As List(Of AutoCompleteSelectListItem), htmlAttributes As Object) As MvcHtmlString Dim selectBuilder As New TagBuilder("select")

How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?

送分小仙女□ 提交于 2019-11-27 07:21:09
I'm building an ASP.NET MVC application, using VB.NET and I'm trying to apply a css class to a Html.ActionLink using the code: <%=Html.ActionLink("Home", "Index", "Home", new {@class = "tab" })%> But when I run the code I receive the below error: Compiler Error Message: BC30988: Type or 'With' expected. I'm new to MVC and really haven't much of a clue what I'm doing so I can't see what's wrong there as I'm using code based of an example elsewhere. It is: <%=Html.ActionLink("Home", "Index", MyRouteValObj, new with {.class = "tab" })%> If VB.net you set an anonymous type using new with {.class =

how to pass parameter with @url.action to controller

江枫思渺然 提交于 2019-11-27 06:36:31
问题 i have following code snippet i want to pass data-id="0" with my @url.action , how can i do this <a class="v-patient pointer" data-id="0" href="@Url.Action("View1", "Task")">View Patient</a></td> my task controller public ActionResult View1(string id) { return View(); } 回答1: If is was an ActionLink you would do this: @Html.ActionLink("View1", "Task", new {id=0}, null); So in your case, using Url.Action() it would be: href="@Url.Action("View1", "Task", new {id=0})" Which in your sample is: <a

Using ViewModel Pattern with MVC 2 Strongly Typed HTML Helpers

£可爱£侵袭症+ 提交于 2019-11-27 05:25:16
问题 I am working with ASP.NET MVC2 RC and can't figure out how to get the HTML helper, TextBoxfor to work with a ViewModel pattern . When used on an edit page the data is not saved when UpdateModel() is called in the controller. I have taken the following code examples from the NerdDinner application. Edit.aspx <%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.DinnerFormViewModel>" %> ... <p> // This works when saving in controller (MVC 1) <label for="Title">Dinner

MVC 3: Conditionally Adding the Disabled Attribute with the HtmlHelpers

本秂侑毒 提交于 2019-11-27 05:23:37
问题 I have an ASP.Net MVC 3 web application and I am adding a check box to a view page using the HtmlHelper class, like this... @Html.CheckBox("CheckBox1", true, new { @class = "Class1" }) What I want to do is conditionally add the disabled attribute based on a view state property. Basically the following would be ideal... @Html.CheckBox("CheckBox1", true, new { @class = "Class1", @disabled = Model.ReadOnly }) Unfortunately, due to the nature of the disabled attribute, this will not work because

How to create a readonly textbox in ASP.NET MVC3 Razor

安稳与你 提交于 2019-11-27 05:20:37
问题 How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine? Is there an HTMLHelper method available to do that? Something like the following? @Html.ReadOnlyTextBoxFor(m => m.userCode) 回答1: @Html.TextBoxFor(m => m.userCode, new { @readonly="readonly" }) You are welcome to make an HTML Helper for this, but this is simply just an HTML attribute like any other. Would you make an HTML Helper for a text box that has other attributes? 回答2: UPDATE: Now it's very simple to add HTML

How to remove the default link color of the html hyperlink 'a' tag?

无人久伴 提交于 2019-11-27 05:02:27
问题 The default link color is blue. How to remove the default link color of the html hyperlink tag <a> ? 回答1: The inherit value: a { color: inherit; } … will cause the element to take on the colour of its parent (which is what I think you are looking for). 回答2: you can do some thing like this: a { color: #0060B6; text-decoration: none; } a:hover { color:#00A0C6; text-decoration:none; cursor:pointer; } 回答3: .cancela,.cancela:link,.cancela:visited,.cancela:hover,.cancela:focus,.cancela:active{

ASP.NET MVC 3 Custom HTML Helpers- Best Practices/Uses

拈花ヽ惹草 提交于 2019-11-27 04:57:49
问题 New to MVC and have been running through the tutorials on the asp.net website. They include an example of a custom html helper to truncate long text displayed in a table. Just wondering what other solutions people have come up with using HTML helpers and if there are any best practices or things to avoid when creating/using them. As an example, I was considering writing a custom helper to format dates that I need to display in various places, but am now concerned that there may be a more

Html.ActionLink cannot be dynamically dispatched

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 04:06:14
问题 I have a problem with MVC3 I'm trying to use @Html.ActionLink() to generate a Link for titles in my blog project. Using constant strings in ActionLink works just dandy, but if I use Posts.Title (the Title of the current Post model being looped), I get this exception: CS1973: 'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'ActionLink' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic