html-helper

MVC Html.LabelFor tooltip

纵饮孤独 提交于 2020-01-30 12:11:10
问题 Trying find out how to add a bit more space between the icon and the text <td>@Html.LabelFor(m => m.MiscellaneousSettings.StudentPhotoUrl, new { @class = "fa fa-question-circle", Title = "SomeTooltips" }) </td> As you can see its really close: 回答1: Add this in your css: label.fa:before { margin-right: 5px; } Which will result in: See this JSFiddle. 回答2: Add a space before the student photo URL <td>@Html.LabelFor(m => " " + m.MiscellaneousSettings.StudentPhotoUrl, new { @class = "fa fa

Undefined method when creating a helper in Rails

穿精又带淫゛_ 提交于 2020-01-24 20:15:10
问题 I tried to create a helper module to be able to set the title of a page. Of course it's not working (reference) Is there something I must define in a controller for my helpers methods to be seen by my controllers?? Gitlink: works_controller.rb def index set_title("Morning Harwood") @works = Work.all respond_to do |format| format.html # index.html.erb format.json { render json: @works} end end In application_helper.rb: module ApplicationHelper def set_title(title = "Default title") content_for

Why I cant use Html.RenderPartial in razor helper view File in App_Code Folder?

孤者浪人 提交于 2020-01-23 05:49:04
问题 Simple Razor Helper in App_Code Folder: MyHelper.cshtml @using System.Web.Mvc @helper SimpleHelper(string inputFor){ <span>@inputFor</span> Html.RenderPartial("Partial"); } Simple View in Views/Shared Folder: MyView.cshtml <html> <head </head> <body> @WFRazorHelper.SimpleHelper("test") </body> </html> Simple Partial View in Views/Shared Folder: Partial.cshtml <h1>Me is Partial</h1> Compiler throws an Error: CS1061: 'System.Web.WebPages.Html.HtmlHelper' enthält keine Definition für

Filter a model's attributes before outputting as json

纵然是瞬间 提交于 2020-01-21 12:25:29
问题 Hey guys, I need to output my model as json and everything is going fine. However, some of the attributes need to be 'beautified' by filtering them through some helper methods, such as number_to_human_size . How would I go about doing this? In other words, say that I have an attribute named bytes and I want to pass it through number_to_human_size and have that result be output to json. I would also like to 'trim' what gets output as json if that's possible, since I only need some of the

Create CheckboxFor MVC helper with title attribute from model description

南楼画角 提交于 2020-01-21 12:08:04
问题 I've created a text box helper to add a title (tooltip) taken from the description attribute for the field in a model: public static MvcHtmlString TextBoxForWithTitle<Tmodel, TProperty>(this HtmlHelper<Tmodel> htmlHelper, Expression<Func<Tmodel, TProperty>> expression, object htmlAttributes = null) { var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string htmlFieldName = ExpressionHelper.GetExpressionText(expression); string textboxText = metaData

HTML.HiddenFor value set

*爱你&永不变心* 提交于 2020-01-20 15:22:06
问题 @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", @value = '@Model.title'}) it doesen't work! how to set the value? 回答1: You shouldn't need to set the value in the attributes parameter. MVC should automatically bind it for you. @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField" }) 回答2: For setting value in hidden field do in the following way: @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", Value = @Model.title}) It will work 回答3:

Custom html helpers: Create helper with “using” statement support

流过昼夜 提交于 2020-01-19 04:32:05
问题 I'm writing my first asp.net mvc application and I have a question about custom Html helpers: For making a form, you can use: <% using (Html.BeginForm()) {%> *stuff here* <% } %> I would like to do something similar with a custom HTML helper. In other words, I want to change: Html.BeginTr(); Html.Td(day.Description); Html.EndTr(); into: using Html.BeginTr(){ Html.Td(day.Description); } Is this possible? 回答1: Here is a possible reusable implementation in c# : class DisposableHelper :

to get CHM details from help ID

微笑、不失礼 提交于 2020-01-17 06:10:13
问题 I have Help string id and some CHM files Through the help string, I want to find details like CHM file name, the page linked to that help id, description, title etc of that page. I have all the code to perform string search on multiple CHM files,if you have file name and search criteria. but my concern is ,only if help id is available, so how can i find topic name ,chm name etc. Is that possible to find details of chm files through help id ? 回答1: You may know a CHM is something like a zipped

update .html with @HTML helper DropDownList

醉酒当歌 提交于 2020-01-16 05:24:28
问题 MVC4, C#, jQuery, Razor view (.cshtml) I'm trying to update the .html() of a node with a @HTML.DropDownList: <script type="text/javascript"> $('#CmpMASttF').html('@Html.DropDownList("CmpAdrsSt.State", (IEnumerable<SelectListItem>)ViewBag._State) @Html.ValidationMessageFor(m => m.CmpAdrsSt.State) '); </script> This works fine for a @HTML.EditorFor: $('#CmpMASttF').html('@Html.EditorFor(m => m.CmpAdrsSt.State) @Html.ValidationMessageFor(m => m.CmpAdrsSt.State) '); This is the node being updated

How to read name of html helper element

只愿长相守 提交于 2020-01-13 08:51:11
问题 Is there in mvc any opportunity to read a name which will be assigned to html control? For example I use this code: <div> @Html.LabelFor(x => x.Name) @Html.TextBoxFor(x => x.Name) @Html.ValidationMessageFor(x => x.Name) @Html.HiddenFor(x => x.Id) <div> I want to display here a TextBox name </div> </div> And I want to get a name of input name. This code is fragment of partial view. Name of element looks like children[1].Name 回答1: @Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(