2015-08-09 99 views
0
Good day! 

我尝试学习ASP MVC vNext(6?),所以我用this tutorial,但是当我键入此代码:'URL' 不包含定义 'RouteUrl'

[HttpPost] 
    public void CreateTodoItem([FromBody] TodoItem item) 
    { 

     item.Id = 1 + _items.Max(x => (int?)x.Id) ?? 0; 
     _items.Add(item); 

     string url = Url.RouteUrl("GetByIdRoute", new { id = item.Id }, 
       Request.Scheme, Request.Host.ToUriComponent()); 

     Context.Response.StatusCode = 201; 
     Context.Response.Headers["Location"] = url; 
    } 

我有错误消息:'Url'不包含'RouteUrl'的定义。

我添加此usings,但它确实没有帮助:

using Microsoft.AspNet.Mvc; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Net.Http.Server; 
using System.Runtime.Remoting.Contexts; 
using System.Security.Policy; 

请帮我解决这个错误!

回答

1

Url.RouteUrl是在System.Web.Mvc.dll程序这么加using System.Web.Mvc;

回首这Url.RouteUrl是在MVC6的Microsoft.AspNet.Mvc命名空间。你似乎有这个,所以我不是100%确定的。可能缺少参考文件或其他编译错误。