目前我这样做:
例如:
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列创建"隐藏字段"来实现.
只是想知道有没有优雅的方式来做到这一点,省力和最佳性能?
我有一个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)
提前致谢.....
我在我的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) 我在复选框列表中有多个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) 我这样做了.
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)
任何帮助将不胜感激.
我正在尝试将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) 我在.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) 例如:我正在调用客户端的以下操作.
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