Commit Graph

56 Commits

Author SHA1 Message Date
Doug Bunting 22fafe298c Add `BeginRouteForm()` HTML helper
- refactor `DefaultHtmlGenerator.GenerateForm()` to support new method

nits:
- correct XML comments
- add a few more code comments
2014-11-12 21:55:40 -08:00
N. Taylor Mullen 09af7bb77b Change TagBuilder Attributes and HTML Helper dependencies to be case insensitive.
- This involved adding the StringComparer.OrdinalIgnoreCase comparer to the TagBuilder's Attributes dictionary.
- Added tests to validate that all methods that made use of TagBuilder.Attributes abide by the new ignore case mechanic.
- Added two sets of tests to validate the new functionality of Object => Dictionary HTML helper tests.
- Modified a functional test that utilizes HTML Helpers to provide same attribute-different case objects.
- Fixed existing HTML helper tests to account for new ordering of attrbutes (dictionary no longer adds key value pairs, it sets them).

#1328
2014-10-26 13:15:09 -07:00
Doug Bunting dd5da33a62 Sanitize "id" attributes for HTML 4.0.1
- #704 part 2 of 2
- change `@Html.Id()` to sanitize return value; was identical to `@Html.Name()`

Copied `TagBuilder.CreateSanitizedId()` and `TagBuilder.Html401IdUtil` from MVC 5.2
- except this `CreateSanitizedId()` returns a valid identifier if first `char` is not a letter
 - e.g. "[0].Name"

nits:
- expand variable names, use lots of `var`, put `public` members first
- add doc comments for `CreateSanitizedId()`

Note users will be able to apply different sanitization once we fix #1188.
2014-10-17 16:12:45 -07:00
Doug Bunting f9e44ff7f9 Correct initialization of `IdAttributeDotReplacement
- #704 part 1 of 2
- doesn't help tag builders unless done in `DefaultHtmlGenerator`
2014-10-17 16:12:22 -07:00
Doug Bunting 3b7b0f867d Update `HtmlHelper` to use `IHtmlGenerator`
- make a few more methods available as `internal static` in `DefaultHtmlGenerator`
 - remove `IHtmlGenerator.GenerateOption()`; now `internal static`

nits:
- add `IHtmlGenerator.IdAttributeDotReplacement`
- move `DefaultHtmlGenerator.IdAttributeDotReplacement` after constructor
- move `HtmlHelper.ActionLink()` below static methods
- move newly-`internal` methods together in `DefaultHtmlGenerator`
- correct placement of `DefaultHtmlGenerator.GetValidationAttributes()` comment
2014-10-16 21:12:34 -07:00
Doug Bunting 339c63d143 Add `IHtmlGenerator` and its default implementation
- part of #1243 (kind-of)
- mostly copied from `HtmlHelper` but refactored to
 - consistently take a `ViewContext` parameter and return a `TagBuilder`
 - provide `GenerateActionLink()` and `GenerateRouteLink()`
 - provide a separate `GenerateHiddenForCheckBox()`, allowing
   `GenerateCheckBox()` to return a `TagBuilder`
 - `GenerateForm()`'s `method` parameter is a `string`, not `FormMethod`

nits: format document, consistent line wrapping, variable name changes, ...
2014-10-16 21:08:59 -07:00
Pranav K 18e11f546d DecorateWriter does not get called for partial views rendered via
Html.PartialAsync

* Introducing StringCollectionTextWriter to buffer the contents of
  PartialAsync
* Ensure DecorateWriter is called for partial views

Fixes #1266
2014-10-12 14:24:29 -07:00
Kiran Challa fdeff1188b [Fixes #926] Protocol & Host name ignored when creating action link 2014-09-26 17:20:56 -07:00
Pranav K d604c18368 Moving IModelValidatorProvider to Options
Fixes #879
2014-08-26 11:53:32 -07:00
dougbu 0b548997d2 Back `HtmlHelper.Html5DateRenderingMode` with new `ViewContext` property
- provides expected scoped semantics
- helps a bit with #448 but does not provide an app-wide default
2014-08-20 10:08:12 -07:00
dougbu 77066a3ade Improve XML comments in `HtmlHelper` and related classes and interfaces
- #847 line 1: copy XML comments from interfaces to extension methods
- lots of wording changes to be more consistent
 - core text split from PR #866, where @rynowak and I hashed out the words
 - to extent possible, reuse words between method descriptions

- add a few missing `<param/>` and `<typeparam/>` elements and fill in empty ones
- display more HTML elements as tags
- use `<c>true|false|null</c>` more often
- add `<remarks/>` describing behaviour of input helpers e.g. `CheckBox()`
- add `<remarks/>` explaining "renders"
- add `<remarks/>` containing example expression names

nits:
- "The expression" -> "An expression"
- make examples for `ObjectToDictionary()` and `AnonymousObjectToHtmlAttributes()` more consistent
- move `<typeparam/>` elements (that existed) after all `<param/>` elements
- explain "checked" attributes better, removing some duplicated words from the `RadioButton[For]()` descriptions
- correct `routeValues` description in `GenerateForm()` comments
2014-08-14 10:42:57 -07:00
dougbu 147b4416b5 Correct gaps in PR #934
- correct XML comment typo introduced in `HtmlHelper` in 56d66c090e (bad merge)
- fix missed `null` requirement for `@Html.RadioButtonFor()` and remove buried `null` check
- add back `Environment.Newline` to `@Html.TextArea()` (was dropped though comment wasn't)
2014-08-07 16:16:03 -07:00
dougbu 56d66c090e Make HTML helper `null` handling consistent
- #874 lines 3, 4, and 6
- correct `Value()` to treat a `null` expression name the same as `string.Empty`
- add missing `[NotNull]` attributes in `EditorExtensions` and for `GenerateIdFromName()`
- consistently pass `null` for default expression names to the helpers
 - for example, from extension methods
- add test cases using `null` for expression name

nits:
- correct summary XML comment for `HtmlHelper` class
- use named parameters and prefer interface (not extension) methods in changed calls
- use `string.Empty` instead of `""` in a few tests
2014-08-06 16:04:56 -07:00
dougbu 8ab11bc073 Correct XML comment syntax
- fix problems at least with Roslyn compiler and VS IntelliSense or the Object Browser
 - `<see langref="keyword"/>` generates nothing
 - `<example>` at top level (outside `<summary>`) generates nothing
 - curly braces don't become angle brackets outside `<see cref="reference"/>` references
  - yeah, a point @yishaigalatzer asked about in a previous PR
- `<see href="reference"/>` is not valid
- correct some invalid use of angle brackets and remove useless empty elements
- correct unresolved XML comment references; generally, add namespace prefix

Symptoms for some of the above issues included
- generated XML comments such as `<!-- Badly formed XML comment ... -->`, usually indicating an unclosed element
- generated XML attributes such as `cref="!:..."`, indicating a broken reference
 - in a couple of cases we had `<typeparamref cref="TOption"/>`; attribute should be `"name"`

Few wording changes beyond
- `"opening </form> tag"` -> `"<form> start tag"`
- `"closing </form> tag"` -> `"</form> end tag"`

Also correct two typos in `HtmlHelper`

Will create a unit test to ensure XML syntax doesn't degrade going forward.  Separate PR.
- for now, check using `dir -r *.xml | sls '!'`
2014-08-05 14:24:48 -07:00
dougbu 3db0a80306 Remove HTML helpers with `IDictionary<string, object>` parameters
- see line 2 of #874
- focus on `TextBox[For]()` and `ValidationSummary()`

related fixes included here:
- `TextArea[For]()` documentation incorrectly indicated their `htmlAttributes` parameters were dictionaries
- handle `htmlAttributes` parameters more consistently; create a dictionary only when necessary
2014-08-03 22:37:42 -07:00
dougbu 7845a8fbe1 `@Html.DisplayName()`, `.DisplayText()`, `.Id()`, `.Name()`, `.Value()` return `string`
- fixes #566 and part of #847
- allows compositions such as `@Html.Label("property", Html.Id("property"))`
  and `@Html.Raw(Html.DisplayText("property"))` (this one is not recommended)
- adjust XML comments to match
- add missing XML comments to `HtmlHelperValueExtensions`
- nit: `TInnerModel` -> `TModelItem`

- increase XML comment consistency for changed methods
 - generally make wording more consistent e.g. how we use words such as
   "returns"
 - use `<see langref="string|true|false|null"/>` more
2014-08-01 21:06:20 -07:00
dougbu 7ec4ab021e Make longest `@Html.DisplayForModel()` overload an extension method
- consistent with @Html.EditorForModel()` overloads
2014-07-31 12:01:28 -07:00
dougbu 40eb05f7e4 Improve `HtmlHelper` extension points
- address all of #659 and a bit of #874 (avoid `public virtual` methods in
  `HtmlHelper`)

- make `MetadataProvider` and `GetClientValidationRules()` `public` and
  therefore available to extension methods
- remove unused `GetValidationAttributes()` overload
- make remaining `GetValidationAttributes()` overload (and not
  `GetClientValidationRules()`) `virtual`, allowing derived classes to
  change the attributes without overriding all callers
- reverse `GetValidationAttributes()` and `GetClientValidationRules()`
  parameter order to match precedence
- add `GenerateName()` and `GenerateValidationSummary()` to make
  `protected virtual` method names consistent
- `Name()`, `ValidationSummary()` and `TextArea()` are no longer `virtual`
  because `protected virtual Generate*()` methods exist for all
2014-07-31 12:01:09 -07:00
dougbu b5dcc9895d Fix #620, Remove legacy / non-unobtrusive client side validation
- remove `ViewContext.UnobtrusiveJavaScriptEnabled` property and all references
- avoid `ViewContext.GetFormContextForClientValidation()` calls since
  ternary expression is more explicit and we were inconsistent
- improve `ValidationMessage()` comments
- don't treat `ModelState.IsValid` as if it were still nullable
2014-07-29 10:43:19 -07:00
dougbu 80a27c6f3b Add `ModelMetadata.DisplayName` property
- value comes from `Name` property of `[Display]` attribute
- use new property in `@Html.DisplayName()` and `@Html.Label()`; remove associated TODO comments
2014-07-24 18:31:48 -07:00
Pranav K 47d227cbf2 Modify FindView and FindPartialView to accept ActionContext
Fixes #787
2014-07-24 11:48:23 -07:00
Pranav K 5194adfaf5 Moving IViewEngine to MvcOptions 2014-07-08 17:50:13 -07:00
dougbu 84396ad875 Clean up trailing whitespace in Core project
- checked and found no tabs in this project 😄
2014-06-09 11:56:52 -07:00
Ryan Nowak 69034b78b8 Issue #65 merge RoutingContext and RequestContext
See the relevant PR in aspnet/Routing#60.

This incorporates the breaking changes.
2014-06-06 10:49:55 -07:00
Ryan Nowak cf0304b897 Fixing style issues in Mvc.Core 2014-06-04 20:40:23 -07:00
Tian Pan a6d89c4482 Copy CodePlex #1836 and #1878 fixes over (Fix #296).
This change enables user to specify the tag for the wrapping HTML element
generated from ValidationSummary() and ValidationMessage[For]().

Clean up HtmlHelperValidationExtensions.
2014-06-03 00:18:47 -07:00
dougbu 575daeb0d6 Use `+` rather than explicit `PathString.Add()` overloads 2014-05-11 22:44:34 -07:00
dougbu 37b2bf4997 Fix #522, [MusicStore]: Html.BeginForm() while generating the action url
should consider the application base path
- `request.BasePath` was indeed ignored
- also simplify `formAction` calculation using the higher-level
  `PathString.Add()` overloads
2014-05-11 22:31:28 -07:00
dougbu dd4fa762d5 Change `BeginForm()` to add query string when called without parameters
- use the request's Path and QueryString rather than default Action() return
  value
- actual special case detects all parameter values match the defaults
- this slightly expands the scenarios where the query string is added but
  removes an odd inconsistency between `html.BeginForm()` and (say)
  `html.BeginForm(FormMethod.Post)`

Fixes #278
2014-05-09 10:35:36 -07:00
Andrew Peters f13865dedc Updating copyright headers 2014-05-08 23:01:20 -07:00
sornaks 3b7983181d WebFX 98 - Adding GetValidationAttributes support 2014-05-07 12:52:48 -07:00
dougbu 67b33868a3 Add `ListBox()` and `ListBoxFor()` helper methods
- copy from legacy MVC
- get `ListBox[For]()` methods in correct places and working
 - also usual stuff: `var`, `[NotNull]`, remove `IDictionary<,>` overloads
 - `ListBoxHelper()` -> `GenerateListBox`
 - already had all the bits needed in `GenerateSelect()`
- special-case `null` or empty `name` in GenerateSelect()
 - ensure `ArgumentException` has correct parameter name
 - lower-level problem affected `CheckBox()` as well
- use `ListBox()` and `ListBoxFor()` in MVC sample
 - use `ListBox()` in an editor template
2014-05-05 14:26:06 -07:00
anpete 8208cd6b2f Update file headers 2014-05-01 17:42:33 -07:00
harshgMSFT 3765abdfca Adding Support for LinkGeneration for named Routes.
- Adding HtmlHelpers for route link generation.
- Controller Helpers
- UrlHelper and UrlHelperExtensions
2014-04-30 18:34:46 -07:00
sornaks 185ad31491 Adding an appropriate sample to use ValidationMessage and ValidationMessageFor. 2014-04-30 11:07:02 -07:00
sornaks f17d444b8a Porting the ValidationMessage changes to suit WebFX requirements. 2014-04-30 10:55:45 -07:00
sornaks d63d998e95 Introducing DisplayText, DisplayTextFor, Id, IdFor, IdForModel.
Fixing CachedDataAnnotationsModelMetadata to support NullDisplayText.
2014-04-30 10:23:25 -07:00
sornaks 112a5ddc50 Changes enabling TextArea, TextAreaFor.
Changing the interface to directly include Rows and Columns.
2014-04-30 09:42:07 -07:00
sornaks b899cac4c8 Porting TextAreaHelper from existing MVC code. 2014-04-30 09:35:48 -07:00
sornaks e0592d01af Cleaning up sprinkled null checks and adding it to a centralized place - FromStringExpression 2014-04-30 09:29:30 -07:00
dougbu f7704ba68f Implement `Editor*()` HTML helpers
- copy over legacy `Editor*()` extensions and default editor templates
- get working in the new world
 - usual `var`, `String` -> `string`, `internal` -> `public`, namespaces, ...
 - longest overloads into `IHtmlHelper[<TModel>]` and implementation classes
 - clean up `ViewContext.ViewData` -> `ViewData`, trailing whitespace, long lines
 - remove `MultilineTextTemplate()` since `TextArea()` doesn't exist yet
 - remove `ColorInputTemplate()` since `Color` type doesn't exist
 - use `html.Label()`, not `LabelExtensions.LabelHelper()`: equivalent helper
   is protected.  only downside is potential `ModelMetadata` re-discovery.
 - rename `HtmlInputTemplateHelper()` -> `GenerateTextBox()`
- copy over `Html5DateRenderingMode` and `html.Html5DateRenderingMode` property
 - and get them working in new world
- hook the default editor templates up
- use `Editor()`, `EditorFor()`, `EditorForModel()` in MVC sample
 - add an on-disk editor template to MVC sample
2014-04-28 14:53:07 -07:00
dougbu 66ca046135 Reintroduce `IHtmlHelper` and use it everywhere possible
- no more `IHtmlHelper<object>` in `DefaultDisplayTemplates` and also no
  need for `ViewDataDictionary<object>` in a few places
- mostly removals from `IHtmlHelper<TModel>` but did cleanup comments and
  add `[NotNull]` for `DisplayFor()`, `DisplayNameFor()`,
  `DisplayNameForInnerType()`, and `LabelFor()`
- also add `[NotNull]` for `this` and `Expression` parameters in some
  extension methods
2014-04-28 10:57:36 -07:00
harshgMSFT f26cc51e2e Introducing AntiForgery System :
- Config is cleaned up to not have IAdditionalDataProvider and SuppressIdentityChecks.

- Added a DefaultClaimUidExtractor which looks for NameIdentifier and if not present serializes entire claims.

- Added HtmlHelper.

- AntiForgery now returns an AntiForgeryTokenSet which represents a tuple of cookie and form tokens.
2014-04-24 18:12:11 -07:00
dougbu b8731621df Add default `Display*()` templates
- first get old code in correct spot
- then get default templates working in new world
 - usual things: `[NotNull]`, `var`, internal -> public
 - provide a `HtmlHelper.GenerateOption()` static method
 - pass an `ViewDataDictionary<object>` instance to `TemplateRenderer` constructor
 - run default templates synchronously with an IHtmlHelper<object>
 - copy over resources
 - add Microsoft.Data.Entity reference for EntityState type
- use default templates in MVC sample
 - remove most on-disk overrides of the default templates
2014-04-19 19:00:42 -07:00
dougbu b8eb16d98d Fix #266: Throw when views aren't found at call sites
- note `htmlHelper.Display()` does not throw on failures
2014-04-17 12:05:16 -07:00
harshgMSFT 72732868c6 Adding DisplayName, Label HtmlHelpers. 2014-04-16 11:41:47 -07:00
dougbu 246bb2e3dd Add `DropDownList()` and `DropDownListFor()` HTML helpers
- copy over legacy MVC's `SelectExtensions`, `SelectListItem` and `SelectListGroup`
 - plus expected `SelectList` and `MultiSelectList`
- fixup select HTML helpers to meet WebFx standards and work in new world
 - usual stuff: `[NotNull]`, `var`, `String` -> `string`, long lines, ...
 - remove `IDictionary<string, object> htmlAttributes` overloads
 - move longest extension method overloads into correct classes / interfaces
 - add `ViewDataEvaluator.Eval()` overload for an `object` container
 - rename lower-level helpers to make purposes more obvious
 - nit: move Raw() methods up from bottom of HtmlHelper.cs
- use `DropDownList[For]()` in MVC sample
2014-04-14 16:05:07 -07:00
Ryan Nowak 408d4056b1 Rearrange ViewContext 2014-04-10 11:40:57 -07:00
Ryan Nowak cda73e95a8 Integrate dictionary helper with existing code paths 2014-04-10 11:21:35 -07:00
dougbu 82b071c80e Add CR-requested comment 2014-04-09 14:30:12 -07:00