|
3 | 3 |
|
4 | 4 | using System.ComponentModel.DataAnnotations;
|
5 | 5 | using System.Data.Linq;
|
| 6 | +using System.Linq.Expressions; |
6 | 7 | using System.Web.Mvc.Test;
|
7 | 8 | using System.Web.Routing;
|
8 | 9 | using System.Web.WebPages.Scope;
|
@@ -2147,6 +2148,19 @@ public void RadioButtonForWithNameAndValue()
|
2147 | 2148 | Assert.Equal(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""radio"" value=""ViewDataFoo"" />", html.ToHtmlString());
|
2148 | 2149 | }
|
2149 | 2150 |
|
| 2151 | + [Fact] |
| 2152 | + public void RadioButtonForWithNestedNameAndValue() |
| 2153 | + { |
| 2154 | + // Arrange |
| 2155 | + HtmlHelper<string> helper = MvcHelper.GetHtmlHelper(GetRadioButtonNestedAndUnsetViewData()); |
| 2156 | + |
| 2157 | + // Act |
| 2158 | + MvcHtmlString html = helper.RadioButtonFor(m => m, "ViewItemFoo"); |
| 2159 | + |
| 2160 | + // Assert |
| 2161 | + Assert.Equal(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""radio"" value=""ViewItemFoo"" />", html.ToHtmlString()); |
| 2162 | + } |
| 2163 | + |
2150 | 2164 | [Fact]
|
2151 | 2165 | public void RadioButtonForWithNameAndValue_Unobtrusive()
|
2152 | 2166 | {
|
@@ -3056,6 +3070,31 @@ private static ViewDataDictionary<FooBarModel> GetRadioButtonViewData()
|
3056 | 3070 | return viewData;
|
3057 | 3071 | }
|
3058 | 3072 |
|
| 3073 | + private static ViewDataDictionary<string> GetRadioButtonNestedAndUnsetViewData() |
| 3074 | + { |
| 3075 | + ViewDataDictionary<FooBarModel> viewData = new ViewDataDictionary<FooBarModel> { }; |
| 3076 | + viewData.Model = new FooBarModel { foo = "ViewItemFoo", bar = "ViewItemBar" }; |
| 3077 | + |
| 3078 | + |
| 3079 | + Expression<Func<FooBarModel, string>> containedExpression = m => m.foo; |
| 3080 | + |
| 3081 | + var metadata = ModelMetadata.FromLambdaExpression(containedExpression, viewData); |
| 3082 | + var htmlFieldName = ExpressionHelper.GetExpressionText(containedExpression); |
| 3083 | + |
| 3084 | + |
| 3085 | + ViewDataDictionary nestedViewData = new ViewDataDictionary(viewData) |
| 3086 | + { |
| 3087 | + Model = metadata.Model, |
| 3088 | + ModelMetadata = metadata, |
| 3089 | + TemplateInfo = new TemplateInfo |
| 3090 | + { |
| 3091 | + HtmlFieldPrefix = viewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName), |
| 3092 | + } |
| 3093 | + }; |
| 3094 | + |
| 3095 | + return new ViewDataDictionary<string>(nestedViewData); |
| 3096 | + } |
| 3097 | + |
3059 | 3098 | // TEXTBOX
|
3060 | 3099 | private static readonly RouteValueDictionary _attributesDictionary = new RouteValueDictionary(new { baz = "BazValue" });
|
3061 | 3100 | private static readonly object _attributesObjectDictionary = new { baz = "BazObjValue" };
|
|
0 commit comments