我想我知道答案,但我想反思一些想法.
我想将几个(在这个例子中为2个)一些不同的数据传递给View.我最初的想法是简单地将各种对象包装成一个包含对象并沿着这种方式传递它们.然后从视图中,我会有类似的东西
var objContainer = ViewData.Model;
var thisObject = objContainer.ThisObject;
var thatObject = objContainer.ThatObject;
Run Code Online (Sandbox Code Playgroud)
这些可以在母版页和查看页中单独使用.
这是"最好的"方式吗?
我有2个组件:
大会1:
interface IWeapon {
int Might { get; }
}
[Export("sword")]
public class Sword : IWeapon {
public int Might {
get { return 10; }
}
}
Run Code Online (Sandbox Code Playgroud)
大会2:
interface IWeapon {
int Might { get; }
}
var catalog = new AssemblyCatalog(typeof(Ninja.Sword).Assembly);
var container = new CompositionContainer(catalog);
// not allowed to use the IWeapon def in assembly 2
var sword = container.GetExportedValue<IWeapon>("sword");
Run Code Online (Sandbox Code Playgroud)
我知道如何让它发挥作用.我可以向MEF(Managed Extensibility Framework)询问该对象,或者让它导出正确的IWeapon而不是按名称导出对象.
如果所有接口点都已实现,MEF可以为我做"鸭子"打字并返回代理对象吗?
我有"SQL Native Client",但没有"SQL Server"ODBC驱动程序.我在我的机器上安装了SQL 2005.
试图通过安装SQL Server客户端工具来修复.
任何想法,将不胜感激.
我正在运行Windows XP专业版.
我在为泛型方法指定Type时尝试使用Type参数时收到错误.
错误:'JsonFilter.JsonDataType'是'属性',但用作'类型'
public class JsonFilter : ActionFilterAttribute
{
public Type JsonDataType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
...
JavaScriptSerializer jss = new JavaScriptSerializer();
var result = jss.Deserialize<JsonDataType>(inputContent);//Error here
...
Run Code Online (Sandbox Code Playgroud)
新规范
...
JavaScriptSerializer jss = new JavaScriptSerializer();
MethodInfo method = jss.GetType()
.GetMethod("Deserialize")
.MakeGenericMethod(new Type[] { JsonDataType });
var result = method.Invoke(jss, new object[] { inputContent });
filterContext.ActionParameters[Param] = result;
...
Run Code Online (Sandbox Code Playgroud)
反射节省了一天.感谢@Jason解释当type被指定为泛型方法(< Typename >)的一部分时,它会被编译成字节.而作为属性,它可以是任何类型,只能在运行时确定.
UPDATE
对于此特定问题,以下代码更简洁.
var o = new DataContractJsonSerializer(JsonDataType).ReadObject(
filterContext.HttpContext.Request.InputStream);
filterContext.ActionParameters[Param] = o;
Run Code Online (Sandbox Code Playgroud) 我觉得这个问题很愚蠢,但是必须有一个衬垫能够在c#中执行与下面相同或近似相同的代码...所以你能告诉我它是什么吗?
public static string[] ToStringArray(int[] i)
{
if (i==null) return null;
string[] result = new string[i.Length];
for (int n= 0; n< result.Length; n++)
result[n] = i[n].ToString();
return result;
}
Run Code Online (Sandbox Code Playgroud) 我在ASP中维护一个站点,其中一个任务是将焦点设置在页面上的文本框中.这是我尝试过的:
<script type="text/javascript">
<!--
document.psForm['password'].focus();
//AND
document.getElementById("password").focus();
-->
</script>
Run Code Online (Sandbox Code Playgroud)
我认为这不会起作用......而且它没有:
<form id="psForm" action="logonpw.asp" method="post" defaultfocus="password">
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<body onload="javascript:docuument.psForm.password.focus();">
Run Code Online (Sandbox Code Playgroud)
这是表格:
<form id="psForm" action="logonpw.asp" method="post">
<table border="0" cellpadding="5">
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" value="<%= password %>" size="50">
</td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud) 如何在Umbraco 4 的" 创建"对话框中显示现有文档类型.
我安装了BlogForUmbraco4_1.0.0软件包,我意识到它试图安装为主站点,但它还安装了所有必要的文档类型,包括Blog和BlogPost.在我的网站中创建新项目时,为什么它们不是一个选项.
好.我正在尝试编写一个事件接收器,以便用户完全控制他们上传的任何文件.只要我以管理员身份登录,我就能让代码工作.System.UnauthorizedAccessException:> Access is denied. (Exception from HRESULT: x80070005E_ACCESSDENIED))
当我作为贡献者登录并上传文件时,相同的代码会出现异常.
我已经尝试了几个"解决方案"和其他各种方法来解决问题,如下面的注释代码所示.从我读过的内容来看,有必要以某种方式重新创建对象,同时提升权限,以便在相关对象上拥有这些权限.但这两种方法都无法找到该项目.似乎该项目尚未列入清单.哦,这是一个文档库.
//Works as admin
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);//tried putting this at top and bottom of method, thinking perhaps this where the file get put in list.
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (var site = new SPSite(properties.SiteId))
using (var web = site.OpenWeb(properties.RelativeWebUrl))
{
...
//works when admin
var item = properties.ListItem;
//attempt: by item url
//this does not work, file not found
var item = web.GetListItem(properties.ListItem.Url);
//attempt: by item ID …
Run Code Online (Sandbox Code Playgroud) 在经典的asp中你有了Global.asa文件,在.Net中有什么相同的东西?我想要一个中心点来创建(一次)我希望能够在整个应用程序中访问的主DataSet?什么是正确的事件,onStart?
谢谢R.
c# ×3
.net ×1
asp-classic ×1
asp.net ×1
asp.net-mvc ×1
generics ×1
installation ×1
javascript ×1
mef ×1
sharepoint ×1
shortcut ×1
sql-server ×1
umbraco ×1
wss-3.0 ×1