【问题标题】:'Url' does not contain a definition for 'RouteUrl'“Url”不包含“RouteUrl”的定义
【发布时间】:2015-08-12 23:48:28
【问题描述】:
Good day!

我尝试学习 ASP MVC vNext (6?),所以我使用this tutorial,但是当我输入此代码时:

    [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”的定义。

我添加了这个用法,但它没有帮助:

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;

请帮我解决这个错误!

【问题讨论】:

    标签: asp.net-mvc asp.net-web-api


    【解决方案1】:

    Url.RouteUrl 在 System.Web.Mvc.dll 中所以添加using System.Web.Mvc;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      相关资源
      最近更新 更多