在MVC项目中使用System.Device [英] Using System.Device in an MVC project

查看:87
本文介绍了在MVC项目中使用System.Device的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎没有道理.

我正在尝试在项目中使用System.Device库以利用地理位置功能.我通常会在Razor页面上添加代码.

I'm trying to use the System.Device library in a project to take advantage of the geo location functionality. I'm adding code to a Razor page as I usually do.

我有一个关于库的引用,并且已经在razor视图的顶部添加了using:

I have a reference to the library and I've added the using to the top of the razor view:

@using System.Device;

设备带有红色下划线,因为找不到它.键入System.D不会在智能感知中产生Device.这似乎没有意义,因为该库是绝对引用的.

Device has a red underline because it cannot be found. Typing System.D does not yield Device in intellisense. This doesn't seem to make sense as the library is definitely referenced.

在Views中的web.config没有提及System.Device.如果我对设备"的解决方案进行全面搜索,那么在我意料之外的地方都不会提及它.

The web.config is in Views has no mention of System.Device. If I do a full search of the solution for 'device' there are no mentions of it anywhere I wouldn't expect.

我已经打开和关闭文件,删除了引用,重新启动了VS,重新启动了我的计算机.一切.它仍然存在.

I've open and closed files, removed the reference, restarted VS, restarted my computer. Everything. It still persists.

我觉得或者有些我不知道的东西,或者我正在做一些愚蠢的事情.我在这里想念什么吗?

I feel like either there's something I don't know or I'm doing something stupid. Am I missing something here?

推荐答案

该Web.config在视图"中没有提及System.Device.

The web.config is in Views has no mention of System.Device.

您需要将System.Device添加到您的web.config.根据您是否使用区域,可能还需要将其添加到该区域的web.config中.如果不在web.config中,则razor对此一无所知.

You need to add System.Device to your web.config. Depending on whether you're using Areas you may need to add it to the web.config for that area too. If it's not in web.config, razor doesn't know about it.

 <namespaces>
    <add namespace="System.Device" />
 </namespaces>

此外,尝试将System.Device的引用属性的Copy Local设置为True.直到我都做完后,它才对我有用.

Further, try setting Copy Local to True for the Reference Properties of System.Device. It didn't work for me until I did both.

这篇关于在MVC项目中使用System.Device的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆