小编may*_*ayk的帖子

如果返回格式是xml,如何删除web api中的模式节点?

我有一个web api方法,它将format作为一个参数,提供返回xml和json.返回的方法返回的数据类型是DataTable.在json格式中,一切看起来都很好但是在xml格式中,数据表的模式和xml节点中的一些其他属性还返回.如何返回仅包含datatable数据的简单xml?另外,我在WebApiConfig中使用QueryStringMapping.

这是WebApiConfig代码

public static void Register(HttpConfiguration config)
{
    config.MapHttpAttributeRoutes();
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
    config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "json", new MediaTypeHeaderValue("application/json")));
    config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "xml", new MediaTypeHeaderValue("application/xml")));
    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
}
Run Code Online (Sandbox Code Playgroud)

这是控制器方法的伪代码

[BasicAuthentication]
[Route("api/{tablename}")]
[HttpGet]
public IHttpActionResult Get(string tablename, string orders = "", int limit = 100)
{
    DataTable dt = new DataTable{TableName="resource"};
    //... Database connection and getting result
    return Ok(new Response{ limit = limit,count=dt.Rows.Count, data =dt });
}
Run Code Online (Sandbox Code Playgroud)

和响应模型

public class Response
{ …
Run Code Online (Sandbox Code Playgroud)

c# xml xml-formatting asp.net-mvc-5 asp.net-web-api2

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

为什么SignalR改变功能多次击中?

我尝试开发一个asp.net mvc应用程序,并尝试使用signalr.问题是我有两个表来控制项目中的用户通知.我有一个Notification表和NotificationUser表,它是多对多的通知和用户表.我正在尝试,如果用户在系统中向另一个用户创建通知,我会尝试显示一个弹出窗口,用一个简单的消息来确认用户,例如'嘿!收到新通知'.问题是信号器的javascript更改功能击中了这么多次.我在下面列出的signalR中使用了所有步骤

存储过程

    ALTER PROCEDURE [dbo].[GetNotifications]

    @userid int
    AS
    BEGIN
    select n.Ntf_Title,Ntf_Description,n.Ntf_Date from dbo.SysNotifications n INNER JOIN dbo.SysNotificationUser u on  n.Ntf_ID =u.NtU_NtfID where    NtU_UserID=@userid AND NtU_IsRead=0
    END
Run Code Online (Sandbox Code Playgroud)

枢纽

 [HubName("signalRHub")]
 public class NtfHub : Hub
 {
    [HubMethodName("notifyChanges")]
    public static void NotifyChanges()
    {
        var context = GlobalHost.ConnectionManager.GetHubContext<NtfHub>();
        context.Clients.All.notifyChanges();
    }


}
Run Code Online (Sandbox Code Playgroud)

StartUp类

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();

    }
}
Run Code Online (Sandbox Code Playgroud)

部分视图

 [HttpGet]
    public ActionResult GetNtf()
    {

        //NtfRepo rp = new NtfRepo(this.HttpContext);
        string connectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
        int userid =id;
        using …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc sqldependency signalr

5
推荐指数
1
解决办法
1303
查看次数

如何找到 svg 路径的谷歌地图锚点?

问题与谷歌地图标记图标有关。如果我使用默认图标,图标的位置不会改变,但如果我使用 svg,标记的位置会发散。我想使用新的谷歌地图锚点来解决这个问题,但我不知道如何找到我的锚点svg。谁能告诉我这样做可以解决问题,或者我如何找到 svg 的锚点。路径如下。

路径:“M125 410 c-56 -72 -111 -176 -120 -224 -7 -36 11 -83 49 -124 76 -85 223 -67 270 31 28 60 29 88 6 150 -19 51 -122 205 -148 221 -6 3 -32 -21 -57 -54z m110 -175 c35 -34 33 -78 -4 -116 -35 -35 -71 -37 -105 -7 -40 35 -43 78 -11 116 34 41 84 44 120 7z",

svg google-maps google-maps-markers

4
推荐指数
1
解决办法
5648
查看次数