Difference between revisions of ".NET Core MVC Linux Sample"
(→project.json) |
(→MyController.json) |
||
Line 48: | Line 48: | ||
</source> | </source> | ||
− | == MyController. | + | == Programm.cs == |
+ | <source lang="csharp"> | ||
+ | using Microsoft.AspNetCore.Hosting; | ||
+ | |||
+ | namespace aspnetcoreapp | ||
+ | { | ||
+ | public class Program | ||
+ | { | ||
+ | public static void Main(string[] args) | ||
+ | { | ||
+ | var host = new WebHostBuilder() | ||
+ | .UseKestrel() | ||
+ | .UseContentRoot(System.IO.Directory.GetCurrentDirectory()) | ||
+ | .UseStartup<Startup>() | ||
+ | .Build(); | ||
+ | |||
+ | host.Run(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | == MyController.cs == | ||
+ | <source lang="csharp"> | ||
+ | using Microsoft.AspNetCore.Mvc; | ||
+ | |||
+ | namespace aspnetcoreapp | ||
+ | { | ||
+ | public class MapController : Controller { | ||
+ | |||
+ | IOsmService _osmService; | ||
+ | |||
+ | public MapController(IOsmService osmService){ | ||
+ | _osmService = osmService; | ||
+ | } | ||
+ | |||
+ | public string GetString() { | ||
+ | return "Hello World from Controller!"; | ||
+ | } | ||
+ | |||
+ | public ActionResult MyView() | ||
+ | { | ||
+ | MapInfo model = _osmService.LoadCoordinates(); | ||
+ | |||
+ | return View("MyView", model); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
== Model == | == Model == | ||
== View == | == View == |
Revision as of 09:32, 17 September 2016
project.json
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
},
"imports": "dnxcore50",
"frameworkAssemblies": {
}
}
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
}
}
Programm.cs
using Microsoft.AspNetCore.Hosting;
namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(System.IO.Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
MyController.cs
using Microsoft.AspNetCore.Mvc;
namespace aspnetcoreapp
{
public class MapController : Controller {
IOsmService _osmService;
public MapController(IOsmService osmService){
_osmService = osmService;
}
public string GetString() {
return "Hello World from Controller!";
}
public ActionResult MyView()
{
MapInfo model = _osmService.LoadCoordinates();
return View("MyView", model);
}
}
}