Deleted ViewComponentWebSite and tests
This commit is contained in:
parent
9288ab1a34
commit
9539c373ba
15
Mvc.sln
15
Mvc.sln
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 14
|
# Visual Studio 14
|
||||||
VisualStudioVersion = 14.0.23107.0
|
VisualStudioVersion = 14.0.24627.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|
@ -74,8 +74,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebApiCompatShimWebSite", "
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.WebApiCompatShimTest", "test\Microsoft.AspNet.Mvc.WebApiCompatShimTest\Microsoft.AspNet.Mvc.WebApiCompatShimTest.xproj", "{5DE8E4D9-AACD-4B5F-819F-F091383FB996}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.WebApiCompatShimTest", "test\Microsoft.AspNet.Mvc.WebApiCompatShimTest\Microsoft.AspNet.Mvc.WebApiCompatShimTest.xproj", "{5DE8E4D9-AACD-4B5F-819F-F091383FB996}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ViewComponentWebSite", "test\WebSites\ViewComponentWebSite\ViewComponentWebSite.xproj", "{24B59501-5F37-4129-96E6-F02EC34C7E2C}"
|
|
||||||
EndProject
|
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TagHelperSample.Web", "samples\TagHelperSample.Web\TagHelperSample.Web.xproj", "{2223120F-D675-40DA-8CD8-11DC14A0B2C7}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TagHelperSample.Web", "samples\TagHelperSample.Web\TagHelperSample.Web.xproj", "{2223120F-D675-40DA-8CD8-11DC14A0B2C7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TagHelpers", "src\Microsoft.AspNet.Mvc.TagHelpers\Microsoft.AspNet.Mvc.TagHelpers.xproj", "{B2347320-308E-4D2B-AEC8-005DFA68B0C9}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TagHelpers", "src\Microsoft.AspNet.Mvc.TagHelpers\Microsoft.AspNet.Mvc.TagHelpers.xproj", "{B2347320-308E-4D2B-AEC8-005DFA68B0C9}"
|
||||||
|
|
@ -474,16 +472,6 @@ Global
|
||||||
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|x86.ActiveCfg = Release|Any CPU
|
{5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
|
@ -1098,7 +1086,6 @@ Global
|
||||||
{23D30B8C-04B1-4577-A604-ED27EA1E4A0E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
{23D30B8C-04B1-4577-A604-ED27EA1E4A0E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||||
{B2B7BC91-688E-4C1E-A71F-CE948D958DDF} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
{B2B7BC91-688E-4C1E-A71F-CE948D958DDF} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
||||||
{5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
{5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
{24B59501-5F37-4129-96E6-F02EC34C7E2C} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
|
||||||
{2223120F-D675-40DA-8CD8-11DC14A0B2C7} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
|
{2223120F-D675-40DA-8CD8-11DC14A0B2C7} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
|
||||||
{B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
{B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||||
{860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
{860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
|
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|
||||||
{
|
|
||||||
public class ViewComponentTests : IClassFixture<MvcTestFixture<ViewComponentWebSite.Startup>>
|
|
||||||
{
|
|
||||||
public ViewComponentTests(MvcTestFixture<ViewComponentWebSite.Startup> fixture)
|
|
||||||
{
|
|
||||||
Client = fixture.Client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpClient Client { get; }
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> ViewViewComponents_AreRenderedCorrectlyData
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
yield return new[]
|
|
||||||
{
|
|
||||||
"ViewWithAsyncComponents",
|
|
||||||
@"<test-component>value-from-component value-from-view</test-component>
|
|
||||||
ViewWithAsyncComponents InvokeAsync: hello from viewdatacomponent"
|
|
||||||
};
|
|
||||||
|
|
||||||
yield return new[]
|
|
||||||
{
|
|
||||||
"ViewWithSyncComponents",
|
|
||||||
@"<test-component>value-from-component value-from-view</test-component>
|
|
||||||
ViewWithSyncComponents Invoke: hello from viewdatacomponent"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[MemberData(nameof(ViewViewComponents_AreRenderedCorrectlyData))]
|
|
||||||
public async Task ViewViewComponents_AreRenderedCorrectly(string actionName, string expected)
|
|
||||||
{
|
|
||||||
// Arrange & Act
|
|
||||||
var body = await Client.GetStringAsync("http://localhost/Home/" + actionName);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(expected, body.Trim(), ignoreLineEndingDifferences: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ViewComponents_SupportsValueType()
|
|
||||||
{
|
|
||||||
// Arrange & Act
|
|
||||||
var body = await Client.GetStringAsync("http://localhost/Home/ViewWithIntegerViewComponent");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal("10", body.Trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ViewComponents_InvokeWithViewComponentResult()
|
|
||||||
{
|
|
||||||
// Arrange & Act
|
|
||||||
var body = await Client.GetStringAsync("http://localhost/ViewComponentResult/Invoke?number=31");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal("31", body.Trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingWhere", "Where")]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingSelect", "Select")]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingSelectMany", "SelectMany")]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingTake", "Take")]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingTakeWhile", "TakeWhile")]
|
|
||||||
[InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingUnion", "Union")]
|
|
||||||
public async Task ViewComponents_SupportsEnumerableModel(string url, string linqQueryType)
|
|
||||||
{
|
|
||||||
// Arrange & Act
|
|
||||||
// https://github.com/aspnet/Mvc/issues/1354
|
|
||||||
// The invoked ViewComponent/View has a model which is an internal type implementing Enumerable.
|
|
||||||
// For ex - TestEnumerableObject.Select(t => t) returns WhereSelectListIterator
|
|
||||||
var body = await Client.GetStringAsync(url);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal("<p>Hello</p><p>World</p><p>Sample</p><p>Test</p>"
|
|
||||||
+ "<p>Hello</p><p>World</p><p>" + linqQueryType + "</p><p>Test</p>", body.Trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("ViewComponentWebSite.Namespace1.SameName")]
|
|
||||||
[InlineData("ViewComponentWebSite.Namespace2.SameName")]
|
|
||||||
public async Task ViewComponents_FullName(string name)
|
|
||||||
{
|
|
||||||
// Arrange & Act
|
|
||||||
var body = await Client.GetStringAsync("http://localhost/FullName/Invoke?name=" + name);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(name, body.Trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ViewComponents_ShortNameUsedForViewLookup()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var name = "ViewComponentWebSite.Integer";
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var body = await Client.GetStringAsync("http://localhost/FullName/Invoke?name=" + name);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal("17", body.Trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -58,7 +58,6 @@
|
||||||
"ValidationWebSite": "1.0.0",
|
"ValidationWebSite": "1.0.0",
|
||||||
"ValueProvidersWebSite": "1.0.0",
|
"ValueProvidersWebSite": "1.0.0",
|
||||||
"VersioningWebSite": "1.0.0",
|
"VersioningWebSite": "1.0.0",
|
||||||
"ViewComponentWebSite": "1.0.0",
|
|
||||||
"WebApiCompatShimWebSite": "1.0.0",
|
"WebApiCompatShimWebSite": "1.0.0",
|
||||||
"XmlFormattersWebSite": "1.0.0",
|
"XmlFormattersWebSite": "1.0.0",
|
||||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class EnumerableViewComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public IViewComponentResult Invoke(string linqQueryType)
|
|
||||||
{
|
|
||||||
var modelList = new List<SampleModel>()
|
|
||||||
{
|
|
||||||
new SampleModel { Prop1 = "Hello", Prop2 = "World" },
|
|
||||||
new SampleModel { Prop1 = linqQueryType, Prop2 = "Test" },
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (linqQueryType) {
|
|
||||||
case "Where":
|
|
||||||
return View(modelList.Where(e => e != null));
|
|
||||||
|
|
||||||
case "Take":
|
|
||||||
return View(modelList.Take(2));
|
|
||||||
|
|
||||||
case "TakeWhile":
|
|
||||||
return View(modelList.TakeWhile(a => a != null));
|
|
||||||
|
|
||||||
case "Union":
|
|
||||||
return View(modelList.Union(modelList));
|
|
||||||
|
|
||||||
case "SelectMany":
|
|
||||||
var selectManySampleModelList = new List<SelectManySampleModel>
|
|
||||||
{
|
|
||||||
new SelectManySampleModel {
|
|
||||||
TestModel =
|
|
||||||
new List<SampleModel> { new SampleModel { Prop1 = "Hello", Prop2 = "World" } } },
|
|
||||||
new SelectManySampleModel {
|
|
||||||
TestModel =
|
|
||||||
new List<SampleModel> { new SampleModel{ Prop1 = linqQueryType, Prop2 = "Test" } } }
|
|
||||||
};
|
|
||||||
|
|
||||||
return View(selectManySampleModelList.SelectMany(a => a.TestModel));
|
|
||||||
};
|
|
||||||
|
|
||||||
return View(modelList.Select(e => e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class FullNameController : Controller
|
|
||||||
{
|
|
||||||
public IActionResult Invoke(string name)
|
|
||||||
{
|
|
||||||
ViewBag.Name = name;
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class HomeController : Controller
|
|
||||||
{
|
|
||||||
private IEnumerable<SampleModel> ModelList { get; set; }
|
|
||||||
|
|
||||||
public HomeController()
|
|
||||||
{
|
|
||||||
ModelList = new List<SampleModel>()
|
|
||||||
{
|
|
||||||
new SampleModel { Prop1 = "Hello", Prop2 = "World" },
|
|
||||||
new SampleModel { Prop1 = "Sample", Prop2 = "Test" },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewWithAsyncComponents()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewWithSyncComponents()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewWithIntegerViewComponent()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingWhere()
|
|
||||||
{
|
|
||||||
ViewBag.LinqQueryType = "Where";
|
|
||||||
return View("ViewComponentWithEnumerableModel", ModelList.Where(a => a != null));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingSelect()
|
|
||||||
{
|
|
||||||
ViewBag.LinqQueryType = "Select";
|
|
||||||
return View("ViewComponentWithEnumerableModel", ModelList.Select(a => a));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingTake()
|
|
||||||
{
|
|
||||||
ViewBag.LinqQueryType = "Take";
|
|
||||||
return View("ViewComponentWithEnumerableModel", ModelList.Take(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingTakeWhile()
|
|
||||||
{
|
|
||||||
ViewBag.LinqQueryType = "TakeWhile";
|
|
||||||
return View("ViewComponentWithEnumerableModel", ModelList.TakeWhile(a => a != null));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingUnion()
|
|
||||||
{
|
|
||||||
ViewBag.LinqQueryType = "Union";
|
|
||||||
return View("ViewComponentWithEnumerableModel", ModelList.Union(ModelList));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult ViewComponentWithEnumerableModelUsingSelectMany()
|
|
||||||
{
|
|
||||||
var selectManySampleModelList = new List<SelectManySampleModel>
|
|
||||||
{
|
|
||||||
new SelectManySampleModel {
|
|
||||||
TestModel =
|
|
||||||
new List<SampleModel> { ModelList.ElementAt(0) } },
|
|
||||||
new SelectManySampleModel {
|
|
||||||
TestModel =
|
|
||||||
new List<SampleModel> { ModelList.ElementAt(1) } }
|
|
||||||
};
|
|
||||||
|
|
||||||
ViewBag.LinqQueryType = "SelectMany";
|
|
||||||
return View("ViewComponentWithEnumerableModel", selectManySampleModelList.SelectMany(s => s.TestModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class IntegerViewComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public IViewComponentResult Invoke()
|
|
||||||
{
|
|
||||||
return Invoke(17);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IViewComponentResult Invoke(int valueFromView)
|
|
||||||
{
|
|
||||||
return View(valueFromView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite.Namespace1
|
|
||||||
{
|
|
||||||
// The full name is different here from the other view component with the same short name.
|
|
||||||
public class SameNameViewComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public string Invoke()
|
|
||||||
{
|
|
||||||
return "ViewComponentWebSite.Namespace1.SameName";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite.Namespace2
|
|
||||||
{
|
|
||||||
// The full name is different here from the other view component with the same short name.
|
|
||||||
public class SameNameViewComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public string Invoke()
|
|
||||||
{
|
|
||||||
return "ViewComponentWebSite.Namespace2.SameName";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class SampleModel
|
|
||||||
{
|
|
||||||
public string Prop1 { get; set; }
|
|
||||||
|
|
||||||
public string Prop2 { get; set; }
|
|
||||||
|
|
||||||
public Task<string> GetValueAsync()
|
|
||||||
{
|
|
||||||
return Task.FromResult(Prop1 + " " + Prop2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class SelectManySampleModel
|
|
||||||
{
|
|
||||||
public List<SampleModel> TestModel { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
// Add MVC services to the services container
|
|
||||||
services.AddMvc();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app)
|
|
||||||
{
|
|
||||||
app.UseCultureReplacer();
|
|
||||||
|
|
||||||
app.UseMvcWithDefaultRoute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class TestViewComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public IViewComponentResult Invoke(string valueFromView)
|
|
||||||
{
|
|
||||||
var model = new SampleModel
|
|
||||||
{
|
|
||||||
Prop1 = "value-from-component",
|
|
||||||
Prop2 = valueFromView
|
|
||||||
};
|
|
||||||
return View(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
public class ViewComponentResultController : Controller
|
|
||||||
{
|
|
||||||
public IActionResult Invoke(int number)
|
|
||||||
{
|
|
||||||
return ViewComponent("Integer", number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGuid>24b59501-5f37-4129-96e6-f02ec34c7e2c</ProjectGuid>
|
|
||||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
|
||||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<DevelopmentServerPort>40957</DevelopmentServerPort>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
|
|
||||||
namespace ViewComponentWebSite
|
|
||||||
{
|
|
||||||
[ViewComponent(Name = "ViewData")]
|
|
||||||
public class ViewDataComponent : ViewComponent
|
|
||||||
{
|
|
||||||
public IViewComponentResult Invoke()
|
|
||||||
{
|
|
||||||
ViewData["value-from-component"] = nameof(Invoke) + ": hello from viewdatacomponent";
|
|
||||||
return View("ComponentThatReadsViewData");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IViewComponentResult> InvokeAsync()
|
|
||||||
{
|
|
||||||
ViewData["value-from-component"] = nameof(InvokeAsync) + ": hello from viewdatacomponent";
|
|
||||||
var result = View("ComponentThatReadsViewData");
|
|
||||||
return Task.FromResult<IViewComponentResult>(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
@Component.Invoke(ViewBag.Name)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
@model IEnumerable<SampleModel>
|
|
||||||
@foreach (var m in Model)
|
|
||||||
{<p>@m.Prop1</p><p>@m.Prop2</p>}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
@model int
|
|
||||||
@Model
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
@model SampleModel
|
|
||||||
<test-component>@await Model.GetValueAsync()</test-component>
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
@ViewData["value-from-view"] @ViewData["value-from-component"]
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
@model IEnumerable<SampleModel>
|
|
||||||
@foreach (var m in Model)
|
|
||||||
{<p>@m.Prop1</p><p>@m.Prop2</p>}
|
|
||||||
@Component.Invoke("Enumerable", ViewBag.LinqQueryType)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
@{
|
|
||||||
ViewData["value-from-view"] = ViewContext.ActionDescriptor.Name;
|
|
||||||
}
|
|
||||||
@await Component.InvokeAsync("Test", "value-from-view")
|
|
||||||
@await Component.InvokeAsync("ViewData")
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
@Component.Invoke("Integer", 10)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
@{
|
|
||||||
ViewData["value-from-view"] = ViewContext.ActionDescriptor.Name;
|
|
||||||
}
|
|
||||||
@Component.Invoke("Test", "value-from-view")
|
|
||||||
@Component.Invoke("ViewData")
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
@using ViewComponentWebSite
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"commands": {
|
|
||||||
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
|
|
||||||
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
|
|
||||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
|
||||||
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
|
|
||||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
|
||||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": { },
|
|
||||||
"dnxcore50": { }
|
|
||||||
},
|
|
||||||
"webroot": "wwwroot"
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
ViewComponentsWebSite
|
|
||||||
===
|
|
||||||
|
|
||||||
This web site illustrates how to use custom view components.
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
HelloWorld
|
|
||||||
Loading…
Reference in New Issue