小编10K*_*KY4的帖子

使用Entity Framework仅更新已修改字段的最佳方法

目前我这样做:

例如:

public update(Person model)
{
    // Here model is model return from form on post
    var oldobj = db.Person.where(x=>x.ID = model.ID).SingleOrDefault();
    db.Entry(oldobj).CurrentValues.SetValues(model);
}
Run Code Online (Sandbox Code Playgroud)

它有效,但是,例如,

我的表中有50列但我在表单中只显示了25个字段(我需要部分更新我的表,其余25列保留相同的旧值)

我知道它可以通过"逐列映射"或通过为剩余的25列创建"隐藏字段"来实现.

只是想知道有没有优雅的方式来做到这一点,省力和最佳性能?

asp.net-mvc entity-framework

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

在Javascript函数中获取MVC控制器名称

我有一个Jquery CRUD函数; 这是从几个控制器动作调用的.有没有办法找出哪个控制器正在触发这个功能.

例如; 来自View的函数调用:

$('a.Edit-Icon').live("click", function (event) { 
  editDialog(this, event, '#_List'); 
});
Run Code Online (Sandbox Code Playgroud)

功能参数:

function editDialog(tag, event, target,value)
{
  ------
  // How to get the Controller name ???????????

}
Run Code Online (Sandbox Code Playgroud)

提前致谢.....

javascript asp.net-mvc jquery

10
推荐指数
1
解决办法
1万
查看次数

如何一次加载所有水晶报告页面

我在我的aspx页面中使用CrystalReportViewer.

它工作得很好,但它一次加载一页; 当我在报表中切换页面时,它会回发以获取下一页数据.

在此输入图像描述

每次单击上一个/下一个按钮时,都会显示此加载程序.

在此输入图像描述

是否可以在初始状态下加载所有页面,因此每次都不需要回发和获取数据?

这些是我的Crystalreportsviewer的设置

CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.DisplayToolbar = true;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasToggleParameterPanelButton = false;
CrystalReportViewer1.HasPageNavigationButtons = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
CrystalReportViewer1.HasGotoPageButton = true;
Run Code Online (Sandbox Code Playgroud)

asp.net crystal-reports crystal-reports-viewer

10
推荐指数
1
解决办法
1208
查看次数

在循环中显示多个Crystal Reports

我在复选框列表中有多个Crystal Reports,因此用户可以同时打印/显示多个报表.

目前我正在使用会话传递reportdocument,但大多数时候会话值在分配给crystal报表之前被替换,因此多个报表包含相同的数据.我在每个循环上应用了3秒的延迟,但不是可靠的解决方案.此外,图像不会显示在报告中.

这有什么优雅的技巧吗?

要么

什么是Session变量的替代品?

jQuery的:

$.each(chkBoxarr, function (index, value) {
 var w = window.open();
                $.ajax({
                    type: "POST",
                    url: "PrintReports",
                    traditional: true,
                    data: { id: value},
                    datatype: "json",
                    success: function (data) {
                        w.document.write(data);
                    },
                    error: function () {
                        alert("Error");
                    }
                });
});
Run Code Online (Sandbox Code Playgroud)

控制器:

public ActionResult PrintReports(id)
{
  ReportDocument rpt = new ReportDocument();
  rpt.Load("~/ReportFileName.rpt");
  HttpContext.Session["rpt"] = rpt;
  return Redirect("~/Viewer.aspx");
}
Run Code Online (Sandbox Code Playgroud)

Viewer.aspx.cs

Page_Init(object sender, EventArgs e)
{
    var rpt = System.Web.HttpContext.Current.Session["rpt"];
    CrystalReportViewer1.ReportSource = (ReportDocument)rpt;
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc crystal-reports-2010

9
推荐指数
1
解决办法
1128
查看次数

如何使用RedirectToAction将对象作为隐藏参数传递?

我这样做了.

public ActionResult GetInfo(SomeModel entity)
{
     ----
     return RedirectToAction("NewAction", "NewController", new System.Web.Routing.RouteValueDictionary(entity));
}
Run Code Online (Sandbox Code Playgroud)

被称为的行动

public ActionResult NewAction(SomeModel smodel)
{
     -------
     -------
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我可以在浏览器地址栏上看到所有发布的参数值,如何在浏览器中隐藏这些查询字符串参数值.

http://localhost:51545/NewController/NewAction?SurveyID=13&CatID=1&PrimaryLang=1&SurveryName=Test%20Survery&EnableMultiLang=False&IsActive=False
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

asp.net-mvc

8
推荐指数
1
解决办法
6696
查看次数

使用MVC4向特定客户端发送SignalR推送通知

我正在尝试将SignalR与MVC4 c#项目一起使用,仅向所选客户端发送推送通知.为此我通过在c#静态变量中存储'Context.ConnectionId'来使用'context.Clients.Client',因为无法使用与signalr的会话}.但是因为'contextConnectionId'是一个静态变量; 邮件仍然发送给所有客户:(

是否有任何替代会话与信号或任何其他优雅的方式来做到这一点?(发现很少相关的帖子,但没有具体的答案)

代码如下:

的javaScript

 $(document).ready(function (){
 {
    var chat = $.connection.PushNotify;
    chat.client.addNewMessageToPage = function (type, message) {
        if(type == "something")
        {
            alert(message);
        }
    }
    // Start the connection.
    $.connection.hub.start().done(function () {
        chat.server.send($('').val(), $('').val());
    });
 )}
Run Code Online (Sandbox Code Playgroud)

在c#HUB

[HubName("PushNotify")]
public class PushNotify : Hub
{
    public void Send(string name, string message)
    {
        //assume its c# static variable
        GlobalVariable.contextConnectionId = Context.ConnectionId;
    }
}
public class PushNotification
{
    public void SendMessage(string message, string type = "msg")
    {
        if (!string.IsNullOrEmpty(GlobalVariable.contextConnectionId))
        {
            var context …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4 signalr

8
推荐指数
1
解决办法
1万
查看次数

授权 - GetRolesForUser总是空的?

我在.NET MVC 4应用程序中使用自定义登录验证.但是我无法通过Web.config文件实现角色授权.

我试过如下:

if(loginvalid)
{
    var claimsIdentity = new Claims.ClaimsIdentity(
        new[] 
            { 
                new Claims.Claim(Claims.ClaimTypes.NameIdentifier, "username"),
                new Claims.Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),
                new Claims.Claim(Claims.ClaimTypes.Name,"username"),
                new Claims.Claim(Claims.ClaimTypes.Role, "admin"),
            },
            "CustomApiKeyAuth"
            );

    var principal = new Claims.ClaimsPrincipal(new[] { claimsIdentity });

    System.Threading.Thread.CurrentPrincipal = principal;
    System.Web.HttpContext.Current.User = principal;

    var test1 = User.Identity.IsAuthenticated;

    // here roleNames variable is always empty.
    string[] roleNames = Roles.GetRolesForUser();
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,roleNames变量始终为空.我究竟做错了什么?

和Web.config代码:

<location path="token.axd"> 
    <system.web>
        <authorization>
            <allow roles="admin"/> 
            <deny users="*"/> 
        </authorization>
    </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

authorization roles c#-4.0 asp.net-mvc-4

7
推荐指数
0
解决办法
232
查看次数

在查询字符串中传递'&'作为参数值的一部分的标准方法

例如:我正在调用客户端的以下操作.

Url: /Controller/Action/name?id=12&code=some&code&&
Run Code Online (Sandbox Code Playgroud)

我的参数值是哪里

id = 12
code= 'some&code&&'
Run Code Online (Sandbox Code Playgroud)

但在我的控制器上,我收到了

 id = 12
 code= 'some'
Run Code Online (Sandbox Code Playgroud)

在更糟糕的情况下,我可以通过在两端使用某些字符对"&"进行编码和解码来解决这个问题.

但帽子将是更好的解决方案吗?

我正在寻找具有普通锚标记的解决方案而不是@ Html.ActionLink

asp.net-mvc jquery

2
推荐指数
1
解决办法
394
查看次数