在 MAC 上使用 MonoDevelop 开发 ASP.NET MVC

发布于 2024-11-05 00:27:10 字数 2940 浏览 0 评论 0原文

我正在 MonoDevelop 中使用 ASP.NET MVC 2.0 开发一个 Web 应用程序。我有最新的 Mono 2.10 和 MonoDevelop 2.4.2,我正在 Mac 上运行它们。

根据 mono 的发行说明,它应该支持 ASP.NET MVC 2.0。然而,我发现MonoDevelop的项目模板仍然只支持ASP.NET MVC 1.0。所以我必须从 MonoDevelop 创建 MVC 项目并从引用中删除 system.web.mvc 1.0.0.0 并添加 system.web.mvc 2.0.0.0 回来。我可以编写和编译代码,并且 MonoDevelop 确实为仅存在的方法提供了智能感知在 MVC 2.0 中,来自 C# 和 aspx 文件。然而,当我尝试从 MonoDevelop 运行它时,我遇到了编译错误,抱怨“<%: Html.LabelFor(model => model.Name) %>”因为 LabelFor 方法无法被识别。

MonoDevelop 使用 XSP 作为其测试 Web 服务器。我不确定它是如何配置的,因为我自己没有安装它。我认为它是作为 MonoDevelop 的一部分安装的。我的猜测是 XSP 不知何故仍然使用 MVC 1.0,但我无法证明这一点,因为我什至找不到它的安装位置。

有人可以帮我吗?

更新: 我也一直怀疑web.config。它们现在的样子如下: 网络配置

<configuration>
  <system.web>
    <compilation defaultLanguage="C#" debug="true">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </assemblies>
</compilation>
<customErrors mode="RemoteOnly">
</customErrors>
<pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
  </namespaces>
</pages>
<authorization>
  <allow users="*" />
</authorization>

视图下的 web.config

<configuration>
<system.web>
    <httpHandlers>
        <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
    </httpHandlers>
    <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <controls>
            <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <remove name="BlockViewHandler" />
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>

I am developing a web app using ASP.NET MVC 2.0 in MonoDevelop. I have latest Mono 2.10 and MonoDevelop 2.4.2 and I am running them on Mac.

According to mono’s release notes, it should support ASP.NET MVC 2.0. However, I found MonoDevelop’s project templates still only support ASP.NET MVC 1.0. So I had to create MVC project from MonoDevelop and remove system.web.mvc 1.0.0.0 from reference and add system.web.mvc 2.0.0.0 back in. I can write and compile code OK and MonoDevelop does provide intellisense for methods only exist in MVC 2.0 from both C# and aspx file. However, when I trying to run it from MonoDevelop, I had Compilation error complaining ”<%: Html.LabelFor(model => model.Name) %>” as LabelFor method cannot be recognized .

MonoDevelop uses XSP as its testing web server. I am not sure how it configured as I didn’t install it myself. I think it was installed as part of MonoDevelop. My guess is XSP somehow still uses MVC 1.0 but I can't prove it as I couldn’t even find where it is installed.

Could anyone help me out please?

Update:
I have been suspecting web.config too. Here are how they look like now:
web.config

<configuration>
  <system.web>
    <compilation defaultLanguage="C#" debug="true">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </assemblies>
</compilation>
<customErrors mode="RemoteOnly">
</customErrors>
<pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
  </namespaces>
</pages>
<authorization>
  <allow users="*" />
</authorization>

web.config under views

<configuration>
<system.web>
    <httpHandlers>
        <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
    </httpHandlers>
    <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <controls>
            <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
            namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <remove name="BlockViewHandler" />
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝戈者 2024-11-12 00:27:11

为 ASP.NET MVC 设置 ASP.NET 项目需要在 web.config 中更改和添加大量设置。 MD 中的项目模板适用于 ASP.NET MVC 1.0,而不是 ASP.NET MVC 2,因此您可能缺少一些必要的设置,可能是命名空间导入。

Setting up an ASP.NET project for ASP.NET MVC requires changing and adding a load of settings in web.config. The project template in MD is for ASP.NET MVC 1.0, not ASP.NET MVC 2, so you're probably missing some of the necessary settings, maybe a namespace import.

芸娘子的小脾气 2024-11-12 00:27:11

我在 MacOS X 上运行了我当前的两个项目。我只需要确保完成三个步骤,如下所示:

  • 升级内部(视图)Web 配置和外部中所有引用的版本(应用程序)[你已经完成了这个]。
  • 取消引用 System.Web.MVC 1.0.0.0 和项目参考 2.0.0.0
  • 确保 bin 路径中没有 1.0.0.0 二进制文件,公钥不会更改

I have this running with two of my current projects on MacOS X. There were only three steps I needed to make sure were done, they are as follows:

  • Upgrade the version on all references in both the inner (views) web config and the outter(app) [you've done this].
  • Dereference System.Web.MVC 1.0.0.0 & Reference 2.0.0.0 for the project
  • Ensure you don't have 1.0.0.0 binaries in your bin path, the public key does not change
自此以后,行同陌路 2024-11-12 00:27:11

我已经为 Asp.Net MVC 4 制作了一个可下载的项目模板 zip 文件,该文件在 Mac 和 Mac 上的 Mono/Xamarin Studio/MonoDevelop 上构建并运行。 Linux 位于 http://www.cafe-encounter.net/p1319/run-asp-net-mvc4-on-mono-monodevelop-on-mac-the-c-template-project
我应该补充一点,很多问题解决方案都来自 Razor View 是否引擎适用于 Mono?

I've done a downloadable zip file of a project template for Asp.Net MVC 4 which builds and runs on/in Mono/Xamarin Studio/MonoDevelop on Mac & Linux at http://www.cafe-encounter.net/p1319/run-asp-net-mvc4-on-mono-monodevelop-on-mac-the-c-template-project.
I should add that a lot of the issue resolution came from Does the Razor View Engine work for Mono?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文