html-helper

Render span tag with title attribute with ASP.NET MVC 3 Helpers

心已入冬 提交于 2019-12-03 01:31:23
It's possible to add a HTML title attribute to an input tag like so: @Html.TextBoxFor(model => model.Name, new { title = "Customer name" }) Is there a similar helper for static text? With @Html.DisplayFor(model => model.Name) I can render the text from a model property. How can I add HTML attributes so that I get a span tag rendered like this: <span title="Customer name">ABC</span> Custom html helper is probably the neatest solution. public static MvcHtmlString SpanFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes =

MVC helper - using @URL for image src?

只愿长相守 提交于 2019-12-03 01:30:47
I'm using MVC3 and have a simple helper that draws a box with some text and icons inside for a status application. A snippet: @helper Tile(string ID) { <div class="front defaulttile"> <div class="notifybar" id="NotifyBarID" > <img alt="" src="@Url.Content("~/Images/img.jpg")" style="display: inline; margin-right: 5px;" /> <p class="topstatusbartext" id="NotifyBarTextID" >Status bar text</p> </div> etc... It would be great to use @Url.Content for the image src, but I get an error it's not available. Is there something I can add or change to use this? I'd rather not need to juggle paths and

Html.ActionLink with a specified HTML id?

吃可爱长大的小学妹 提交于 2019-12-03 00:59:10
I'd like to give the like generated with an Html.ActionLink an HTML id so I can change the CSS depending on where I am. I have a MasterPage with a set of links and I'd like to distinguish the active "Tab" with Jquery changing the css of that active #id Right now I'm using: <%: Html.ActionLink("Some View", "Index", "controller")%> It generates: <a href="/controller">Some View</a> I'd like to generate: <a id="something" href="/controller">Some View</a> Is that possible? I've tried: <%: Html.ActionLink("Some View", "Index", "controller", new {id="blahbla")%> But that generates: <a href="

How to Unit Test HtmlHelper with Moq?

我只是一个虾纸丫 提交于 2019-12-02 23:26:18
Could somebody show me how you would go about creating a mock HTML Helper with Moq? This article has a link to an article claiming to describe this, but following the link only returns an ASP.NET Runtime Error [edit] I asked a more specific question related to the same subject here , but it hasn't gotten any responses. I figured it was too specific, so I thought I could get a more general answer to a more general question and modify it to meet my requirements. Thanks What you can do is this: HtmlHelper helper = null; helper.YourHelperMethod(); No need to mock anything. Works brilliant for me.

dropdown in mvc3 edit form

扶醉桌前 提交于 2019-12-02 20:48:12
This maybe very simple but I cant seem to sort it out on my own. I have created a simple db and entity modal that looks like this I am trying to create an Create form that allows me to add a new Order. I have a total of 3 tables so what I am trying to do is have the form allowing the person to enter Order date and also has a dropdown list that allows me to select a product from the product table I want to be able to create a Add or Edit view that allow me to insert the OrderDate into the OrderTable and also insert the OrderID and selected ProductID into OrderProduct. What steps do I need to do

Creating Dropdown List in MVC3

假如想象 提交于 2019-12-02 18:42:50
问题 I am trying to create a dropdown list to display all the value in a custom collection class such as public class MyCustomClassCollection { public List<MyCustomClass> {get;set;} } I want it to show the Description:string of each MyCustomClass I tried <%: Html.DropDownList "Description", MyCustomClass %> Resharper suggests that I cast MyCustomClass to IEnemerable but the server returns an unable to cast error. Any Idea how I can create this DropDownList? __ Modification _ __ public class

Asp.Net MVC 2 Html.TextBoxFor Best way to specify a format string for a DateTime property of model

醉酒当歌 提交于 2019-12-02 18:15:55
As the question title explains, what is the best way to specify a format which my Views use when displaying values of a DateTime property via the Html.TextboxFor method. The default display includes the Date and Time where I really only want the Date displayed. Thanks In your model definition add the DisplayFormatAttribute to the DateTime property: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime Date { get; set; } Then in your View call: <%=Html.EditorFor(m => m.Date)%> If all goes well you should get a TextBox with the value filled in in the

LoadLibrary on OCX file fails in Windows 7 x64

坚强是说给别人听的谎言 提交于 2019-12-02 16:26:53
问题 I need to open a html help file from within a legacy windows application written in old version of C++ Builder. HtmlHelp is loaded via HtmlHelp.ocx, which I am loading via LoadLibrary. This has worked fine for years, but it does not work anymore in Windows 7 x64. It might also fail under Windows7 x86, but I don't have any computer with this OS, so I can't try it out at the moment. I am loading hhctrl.ocx dynamically as follows: #define HHPathRegKey "CLSID\\{adb880a6-d8ff-11cf-9377

Adding CSS class to Html.BeginForm()

醉酒当歌 提交于 2019-12-02 16:04:19
How to add class attribute for following situation (Using ReturnUrl only): @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) { } I want something like this: @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }, new { @class = "login-form" })) { } There is an overload for that, if you supply the controller action, name, and form method. @using (Html.BeginForm("ActionName", "ControllerName", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class="login-form" })) { etc. } p4rds Html.BeginForm("Index", "EIApplication", FormMethod.Post, new { enctype = "multipart

How to change the display name for LabelFor in razor in mvc3?

蓝咒 提交于 2019-12-02 16:03:19
In razor engine I have used LabelFor helper method to display the name But the display name is seems to be not good to display. so i need to change my display name how to do it.... @Html.LabelFor(model => model.SomekingStatus, new { @class = "control-label"}) Darin Dimitrov You could decorate your view model property with the [DisplayName] attribute and specify the text to be used: [DisplayName("foo bar")] public string SomekingStatus { get; set; } Or use another overload of the LabelFor helper which allows you to specify the text: @Html.LabelFor(model => model.SomekingStatus, "foo bar") And,