MVC :: Customize Razor Scaffolding Template Or HTML Helpers?
Feb 2, 2011
I don't know if this is possible but I would like to customize some of the HTML helpers autogenerated in the template. For example, I would like to replace the LabelFor with something that will allow me to specify an image with the label and also a ToolTip property so when you hover over the label you get the tool tip.
I'm trying to write a simple declarative html helper: [Code]....
The helper works fine if I embed it into the page I want to use it on. But if I move it to a separate .cshtml file and place that file in the ~/Views/Helpers directory, my view can't be compiled anymore because the helper is not found.According to Scott Gu's blog article on Razor it should work.
The only workaround I have found so far is placing the Html helper in App_Code and Referencing it as @[MYHTMLHELPERFILENAME].Echo(...) . This works but is a bit messy since I don't want to repeat the name of my extension method (Echo.Echo("inputstring"), nor do I want to put all of my html helpers into one single file (something like MyHtmlHelpers.cshtml).It certainly isn't what Scott announced either, so I guess I must be doing something wrong.
I currently trying to convert a ASP.NET MVC2 application to ASP.NET MVC3 razor. I have a lot custom Html helper methods, which render html output, like the one below, which renders a button with some markup :
Can I seek some advice here if I want to incorporate some automated scaffolding in my MVC 2 web application what is the best way to go? Should I be considering: MVC 2 Templated Helpers, or Dynamic Data (with support for Entity Framework) Roughly speaking I want to layout my own website layout in MVC 2 but then:
for high usage use cases custom define the page, for CRUD maintenance pages hook the website menu to point to some scaffolded auto-generated pages (i.e. it is for this item that I ask the above question). I've had a look at the Dynamic Data pages where you can add/edit/delete all aspects of an EF entity, so it's this type of thing I'm after (e.g. have an Edit Person menu link that when click launches an auto maintenance page for Person)
Starting to get frustrated with MVC and how everything is so helper based with one massive Html helper that just has everything in it. No more controls to inherit from, no events, nothing. I don't see what's the proper way to "customize" something. It's seems it take it or leave it or copy source code and start over again with yet more helper functions. And man, so much stuff in core mvc is internal or private so you end up copying a lot of code but then it won't work. I also don't see any events so that when the core helpers are generating an input element that I can hook in and customize there.
I'm trying to build a forms engine and I like all this new MVC 3 with data annotations, validation, etc. HOWEVER, for all my input controls I need to
1) Add javascript events for onkeydown, onchange, etc
2) Show validation errors using tooltips (was going to use a jqueryui plugin). Based on this, I really just want to place a Html.TextBoxFor and have it generate all the required validation stuff including it's own hidden ! to display should a validation error being present.
I'm using LLBL business objects so it's not so easy to go add attributes like [required] and stuff. Ideally, I'd like to layout the forms once, but then OUTSIDE the form, inside the helpers, or whatever method I use, there I can customize exactly how the input elements and validations are rendered. What is the easiest way to customize, hook, subclass, whatever, the current helpers so that I can generate input elements but with my own project's specific twists?
With the release of mvc 3 rc, I've started playing around with the Razor engine. Has anybody gotten razor templated helpers to work? If so, how? I have a single helper in View/Helpers folder and a single layout page. If I move the code to the view page, it works. The error is ' not in context' for the method name. How and where do I correct this?
When using the template helpers in ASP.NET MVC, e.g. Html.EditorFor(x => x.Property) the rendered Html with have a capitalized ID - matching my property name. In order to standardize the ID's of all html elements I want this to be lower case. Rather than specifying the ID manually - which won't get updated if I rename my property, I'd like to establish a convention. I'm sure I read this was possible somewhere and I'm currently scanning the interwebz to find it.
I have been using web forms and I have been let down by them. I hate the way it mangles my element id's and names. I want to have full control over my html and have the ability to have multiple forms on one page.
I do not use view state or post backs. All my server communication is done using JQuery ajax and sometimes page methods.
My pages do not make use of any runat=server controls other than occasionally using the repeater.
For now I have been using inline code like the following but I like the mvc html helpers.
EXAMPLE:
[Code]....
At the moment, using the asp.net mvc framework is not an option but I would like to use the HTML helpers in my asp.net application.
Is this possible to use the mvc html helpers or do I have to create my ow helpers?
I just upgraded my mvc 1.0 project to 2.0 using the wizard. My project builds fine however, my html helpers that I have used, does not render the input's ID tag. For some reason, only some controls render and some do not. For example:
[code]....
I thought it had to do with the fact that the value is empty, but from the two examples, they are nearly identical. Is this a bug? All was working before I upgraded.
I´m learning mvc and I found a problem. I have a product table that stores currencies in integers. On the other hand I have a table name currency that stores each int id with the currency name.
On html.dropdownlist I followed the pattern:
The name of the form field (ArtistId) The list of values for the dropdown, passed as a SelectList The Data Value field which should be posted back with the form The Data Text field which should be displayed in the dropdown list The Selected Value which is used to set the dropdown list value when the form is displayed
This was great for Forms in order to display selections. Right know I´m finishing my details views and I need to use the int id on product table but display the name on currency table associated to that int id.
Does anyone knows if it exist an html helper that renders the Data Text Field that should be dsiplayed on the View taking into consideration the int number?
Something like @html.display("Name", model.product.currencyid) where name is pulled from db.currency?.
So, most of the MVC examples I find are C#, so I seem to have trouble finding samples ....(bear with me, I'm a newbie) with that said, if anyone can point me in the right direction,
I simply want to be able to apply htmlattributes / styles to my select box
If I wanted to create a custom HTML helper and take advantage of the new in-built templating feature, how would I do that? It appears the templating features are internal?
i wrote mvc 2 application with target framework asp.net 4.0 but my hosting provider supports asp.net 3.5. then i set my project's target framework to 3.5 and i compiled successfully on localhost but when i run the application it says me:
Server Error in '/' application
Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<MvcApplication1.Models.xxx>'.
Source Error:
Line 1: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.xxx>" %>
and visual studio can't see Model and html helpers on view pages.
Was RouteValueDictionary intended for use with htmlAttributes? Is there an alternative? The only 'feature' RouteValueDictionary looks like its got is it has a constructor which accepts an object.
I've just started wokring with Asp.Net mvc and i relay love it. One thing I don't know how to do it yet is:
If I want to develope a new user control (e. g. PeoplePicker) how I get the data? I don't want to use allways ajax requests, some controls should be initialized when the page is loaded. So I could use the Html Helpers and create own extension. So far this is exactly what i want and it's working. But now to the real problem. I can't use dependency injection in extension methods (I'm using spring.net, but the problem should be in all di frameworks).
So which approche is the most common to use this problem? Must I realy pass in the data from my controller? But then the controller must know how my user controls works, I don't want that!