小编Pit*_*ari的帖子

/ signalr/hubs未在asp.net mvc4中加载:抛出404

这就是我做的.

  1. 我用nuget来获取我的MVC4项目的SignalR.
  2. 在我的控制器中创建了一个MyHub类(SignalRTestController.cs)
  3. 在"索引操作"中,尝试从集线器外部广播消息并返回视图.
  4. 在视图中,引用了所有脚本和/ signalr/hubs.

问题是没有找到/ signalr/hubs(抛出404).

我的项目有区域,结构如下所示:

  1. MVCProject
    • 地区
      • 子文件夹
        • 调节器
          • SignalRTestController.cs
        • 模型
        • 视图
          • Index.cshtml
    • 调节器
    • 模型
    • 视图
    • 脚本

signalR的所有脚本都在Scripts文件夹中,我的SignalRTestController.cs看起来像这样:

namespace SignalRTest.Controllers
{
public class SignalRTestController : Controller
{
    public ActionResult Index()
    {
        // Do some work here

        // Broadcasting over a Hub from outside of a Hub
        var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
        context.Clients.say("Hello SignalR!");

       return View();
    }
}

[HubName("MyHub")]
public class MyHub : Hub
{
    public void Say(string message)
    {
        Clients.sendMessage(message);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

任何我的Index.cshtml都引用了所有的javascripts和/ signalr/hubs,如下所示://其他Javascripts

script type …

http-status-code-404 asp.net-mvc-4 signalr signalr-hub

14
推荐指数
2
解决办法
2万
查看次数

使用HTML扩展的值与两个模型具有相同名称的属性时的值不同

这是我的情景.

  1. 创建了两个具有公共属性名称的模型

    public class SimpleModel1
    {
    // Some Properties
    
    public string Property1 { get; set; }
    
    }
    
    public class SimpleModel2
    {
    // Some Properties
    
    public string Property1 { get; set; } // Same name as Property1 in SimpleModel1
    
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在Action(例如Index)中使用SimpleModel1,返回看起来像这样的视图

    @model MvcApplication2.Models.SimpleModel1
    
    @{
    ViewBag.Title = "Home Page";
    }
    
    @using (Html.BeginForm("Test", "Home", FormMethod.Post))
    {
      <label>Enter something here</label>
       @Html.TextBoxFor(m => m.Property1)
       <button type="submit">Submit</button>
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将值提交给将SimpleModel1作为参数的Test操作,做一些工作,并返回一个接受SimpleModel2的视图

    public ActionResult Test(SimpleModel1 model)
    {
        SimpleModel2 newModel = new SimpleModel2();
    
        // Do Something
    
        newModel.Property1 = "Something different …
    Run Code Online (Sandbox Code Playgroud)

properties htmlextensions razor asp.net-mvc-4

6
推荐指数
1
解决办法
1572
查看次数