html-helper

Passing IEnumerable property in RouteValues of ActionLink

最后都变了- 提交于 2019-12-11 10:31:58
问题 Imagine an object defined like : public class MyViewModel{ public List<string> MyList { get; set; } } In my view, i have this Action link : @Ajax.ActionLink("<", "Index", new MyViewModel() { MyList = new List<string>() {"foo", "bar"}}, new AjaxOptions()) The html result of the ActionLink will be : <a class="btn btn-default" data-ajax="true" href="/Index?MyList=System.Collections.Generic.List%601%5BSystem.String%5D"><</a> My question is, how get this result rather : <a class="btn btn-default"

in web2py, can I get newlines in the output of HTML helpers?

非 Y 不嫁゛ 提交于 2019-12-11 08:04:57
问题 I am making a table with web2py HTML helpers. My code is based on the example from the web2py book: >>> table = [['a', 'b'], ['c', 'd']] >>> print TABLE(TR(*table[0]), TR(*table[1])) <table><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table> I have quite a large table, but this approach places all output on one big line. For readability of the HTML, I would appreciate a way to add newlines after each </tr>. I like the HTML helper functions so prefer not to go for the plain {

Persisting Selected Value in MVC DropDownLists

杀马特。学长 韩版系。学妹 提交于 2019-12-11 07:46:29
问题 I'm new to MVC, but I've been all over this, read all the documentation and all the questions and all the blog posts I can find, and all I'm doing is getting completely wrapped around the axle. I'm trying to make a "create" Action and View. My data entry is relatively straight forward, and common: I have a drop down list and a text box. In my case, I'm creating a user contact channel, and the drop down box chooses between email and textmsg, and the text box then enters the relevant contact

Custom HTML Helpers in ASP.NET MVC 2

青春壹個敷衍的年華 提交于 2019-12-11 06:49:30
问题 I want to create a pagination helper. The only parameters that it needs are currentpage, pagecount and routename. However, I do not know if it is possible to use the return value of another html helper inside the definition of my html helper. I am referring specifically to Html.RouteLink. How can I go about doing something like this in the class definition using System; using System.Web.Mvc; namespace MvcApplication1.Helpers { public static class LabelExtensions { public static string Label

How can I create a templated control with Asp.Net MVC?

送分小仙女□ 提交于 2019-12-11 06:11:35
问题 I'm trying to create a templated control with Asp.Net MVC. By templated control, I mean a control that accepts markup as input like so: <% Html.PanelWithHeader() .HeaderTitle("My Header") .Content(() => { %> <!-- ul used for no particular reason --> <ul> <li>A sample</li> <li>A second item</li> </ul> <% }).Render(); %> Note: Yes, this is very similar to how Telerik creates its MVC controls, I like the syntax. Here's my PanelWithHeader code: // Extend the HtmlHelper public static

ASP.NET Core: ShortName in the Display attribute (DataAnnotations)

有些话、适合烂在心里 提交于 2019-12-11 05:29:00
问题 In an ASP .NET Core 1.1 project (VS 2017) I try to use the ShortName attrubute of the Display property in order to use the DisplayFor HTML Helper: [Display(Name="Project Name", ShortName="Name", Description="The name of the project")] public string Name { get; set; } I read the following answer that does the trick for the Description . Unfortunately for a reason I don't understand, this doesn't work for the ShortName . There is the code I tried, the first method seems OK, but the second does

Styling @Html.CheckBoxFor as a slider

若如初见. 提交于 2019-12-11 05:07:51
问题 I'm having trouble styling a checkbox generated by @Html.CheckBoxFor() as a slider. I've identified the "culprit" to be the hidden input field. I've made a fiddle to illustrate the problem. It contains 3 checkboxes - one generated by @Html.CheckBoxFor() , the second one using the code generated by @Html.CheckBoxFor() with the hidden input commented out and the third classic checkbox. You will see the slider is not working for the first one. I do need to use @Html.CheckBoxFor() because I want

Location of HtmlHelper instantiation for ASP.NET MVC

北城以北 提交于 2019-12-11 04:28:58
问题 I am trying to debug a problem where HtmlHelper is null in extension methods. Oddly the debugger claims it's fully populated, however I consistently get null exceptions. I'm trying to figure out where HtmlHelper should being instantiated in an attempt to see where my problem may be. Where should HtmlHelper be Instantiated? Update: In particular I am trying to implement the extension found here, http://chriscavanagh.wordpress.com/2009/06/11/mvc-authorizedactionlink/, within a masterpage. The

Invoke an overloaded generic method on a static class

早过忘川 提交于 2019-12-11 04:07:58
问题 I'm trying to invoke methods on the InputExtensions static class in order to create overloads for the methods on the HtmlHelper class. So anyway, I still couldn't invoke the methods of the InputExtensions class. Here's part of the code that I'm using to do so: Type inputExtensions = typeof(InputExtensions); MethodInfo methodInfo = null; MethodInfo genericMethod = null; switch (propertyViewingMode.ViewingLevel) { case 1: methodInfo = inputExtensions.GetMethod(methodName, new Type[] { typeof

ASP.NET MVC HtmlHelper - how do I write an attribute without a value?

混江龙づ霸主 提交于 2019-12-11 04:06:52
问题 I would like to be able to write attributes without values, such as autofocus . Now, I can do this: @Html.TextBoxFor(m => m.UserName, new { autofocus = true }) But of course this writes: <input id="UserName" type="text" value="" name="UserName" autofocus="True"> Is there a way to get the attribute written without the value? 回答1: Commenter alok_dida is correct. Use: @Html.TextBoxFor(m => m.UserName, new { autofocus = "" }) 回答2: Here's a simple way to achieve what you want. Note that this could