我有一个类别的平面列表,如以下类所示
public class FlatCategoryList
{
public List<FlatCategory> Categories { get; set; }
}
public class FlatCategory
{
public string ID { get; set; }
public string Name { get; set; }
public string ParentID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将我的平面类别列表映射到一个层次结构,如下所示:
public class HieraricalCategoryList
{
public List<Category> Categories { get; set; }
}
public class Category
{
public string ID { get; set; }
public string Name { get; set; }
public string ParentID { get; set; }
public List<Category> ChildCategories …Run Code Online (Sandbox Code Playgroud) 我正试图弄清楚如何根据用户的角色显示/隐藏用户的链接.我知道如何为动作方法设置authorize属性,但是如果用户在我的角色数据库中说管理员或管理员,我就无法在视图中显示链接show hide.
有人可以指向我的任何好文章或代码示例吗?
我在我的MVC项目中输入了以下代码,我输入了管理员和管理员角色.当我登录时,我被重定向回我的主索引,而不是被重定向到我的AdminApp索引.我的代码中出错的任何想法?
[AcceptVerbs(HttpVerbs.Post)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
{
if (!ValidateLogOn(userName, password))
{
return View();
}
FormsAuth.SignIn(userName, rememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
if (User.IsInRole("Administrator") || (User.IsInRole("Manager")))
{
return RedirectToAction("Index", "AdminApp");
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我成功创建了一个Telerik网格来显示产品列表,但是我在添加列时遇到了一些困难,允许用户编辑(我甚至不想在网格中编辑 - 我只是想要一个链接到编辑视图)
当我添加自定义列时,我在调试时在错误屏幕中显示以下行(第24行为红色):
Line 22: columns.Add(o => o.ProductIsActive);
Line 23: columns.Template(o =>
Line 24: {
Line 25:
Line 26: %><%=Html.ActionLink("Edit", "Edit", new { id = o.ProductID })%><% }).Title("Edit");
Run Code Online (Sandbox Code Playgroud)
我的编译器错误消息是编译器错误消息:CS1525:无效的表达式术语')'
这是我的查看代码:
<%= Html.Telerik().Grid<NationalPetVax.Models.Product>()
.Ajax(ajax => ajax.Action("_Index", "Products"))
.DataKeys(dataKeys => dataKeys.Add(c => c.ProductID))
.DataBinding(dataBinding => dataBinding.Ajax().Update("Update", "Home"))
.Name("Grid")
.Columns(columns =>
{
columns.Add(o => o.ProductName).Width(81);
columns.Add(o => o.ProductPrice).Width(200);
columns.Add(o => o.ProductType.ProductTypeName);
columns.Add(o => o.Specy.SpeciesName);
columns.Add(o => o.ProductIsActive);
columns.Template(o =>
{
%><%=Html.ActionLink("Edit", "Edit", new { id = o.ProductID })%><% }).Title("Edit");
})
.Sortable()
.Scrollable() …Run Code Online (Sandbox Code Playgroud) 我在我的控制器上编写了一个方法,为我的客户端自动生成一个powerpoint卡座,所有这些都可以正常工作......除了我关于将文件保存到磁盘的部分.
我对这个概念并不陌生; 并且"认为"我需要做的就是授予IIS_IUSRS对目录的写权限以及对所有父目录的读权限.我正在使用IIS 7,之前我已经使用IIS 6授予NETWORK SERVICE相同的权限.
只是为了踢,我甚至给了每个人对目录的写权限,我仍然得到异常:System.UnauthorizedAccessException:拒绝访问路径'C:......\Content\PPT'.(为简单起见,我删除了一些路径).
还有什么我可以忽略的吗?它所在的服务器是我设置的第一个,所以我可能忽略了一些东西?
这是我的控制器方法简化:
public ActionResult CreatePowerPoint()
{
string path = HttpContext.Server.MapPath("~/Content/PPT");
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation();
CreatePresentation(presentation);
presentation.Save(path, Aspose.Slides.Export.SaveFormat.Ppt);
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
presentation.Save()方法采用路径和保存格式......我不知道还有什么可以尝试...我的代码有问题吗?我是否错误地创建了路径?我也可以将Stream流传递给save方法,但我不确定这是否能解决问题.
我目前在我的MVC应用程序中对过滤器中的授权角色进行硬编码,如下所示:
[Authorize(Roles = "Administrator,Manager")]
Run Code Online (Sandbox Code Playgroud)
我想最终有办法将角色映射到每个控制器,以便站点管理员可以处理分配哪些角色可以执行每组操作.
string roles = DoSomethingToGetAllowableRoles(controllerName);
[Authorize(Roles = roles)]
Run Code Online (Sandbox Code Playgroud)
我想我需要有一个数据库表,以某种方式保存每个控制器的列表,然后另一个表将控制器映射到角色.我想要的是一个页面,我可以列出每个控制器,然后有一组复选框,列出适用于该控制器的每个角色.
任何人都有一个例子,或者可以引导我朝着完成这个目标的方向前进?
我已经实现了自动完成功能,在选择项目后,我在文本框中遇到标签与值的问题.当我输入邮政编码时,我会在下拉列表中看到标签:

但是在我选择一个,而不是显示在文本框中的标签后,将显示值(即需要保存到数据库的ID):

如何在选择标签后仍然显示标签,但是当保存表单时,它会传递字段的ZipCodeID?
这是我的Controller方法:
public JsonResult FindZipCode(string term)
{
VetClinicDataContext db = new VetClinicDataContext();
var zipCodes = from c in db.ZipCodes
where c.ZipCodeNum.ToString().StartsWith(term)
select new { value = c.ZipCodeID, label = c.ZipCodeNum};
return this.Json(zipCodes, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
这是我的标记:
<script type="text/javascript">
$(document).ready(function() {
$("#ZipCodeID").autocomplete({
source: '<%= Url.Action("FindZipCode", "Customers") %>',
});
});
</script>
<div class="ui-widget"><input type="text" name="ZipCodeID" id="ZipCodeID" /></div>
Run Code Online (Sandbox Code Playgroud)
编辑:这是我的最终工作代码:
控制器:
public JsonResult FindZipCode(string term)
{
VetClinicDataContext db = new VetClinicDataContext();
var zipCodes = from c in db.ZipCodes
where c.ZipCodeNum.ToString().StartsWith(term)
select new { …Run Code Online (Sandbox Code Playgroud) 我正在网站上实现Galleria幻灯片,我在大多数情况下都能正常工作.我正在使用api来自定义幻灯片的外观,我想从图像中获取alt文本并显示在div中(我现在只是登录到firebug控制台)
这是我写的脚本:
<script type="text/javascript">
Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
$("#gallery").galleria({
width: 420,
height: 370,
autoplay: 5000, // will move forward every 5 seconds
extend: function(options) {
var gallery = this; // "this" is the gallery instance
this.bind("loadstart", function(e) {
var currImg = gallery.getActiveImage();
var altText = $(currImg).attr('alt');
console.log(altText);
});
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
似乎这会起作用,但我在控制台中"未定义".有谁知道如何从"Galleria"图像中获取alt文本?API文档说.getActiveImage()方法返回一个返回IMG元素,所以我不确定我是否以正确的方式使用IMG元素,或者它是否有我可以抓取的替代文本.
我也试过使用我的图像ID,这是
('slideshow_image_' + e.index)
Run Code Online (Sandbox Code Playgroud)
但这也给了我一个未定义的日志结果.
我知道HTML中有一个名为slideshow_image_0等的元素,我认为按元素ID查找alt文本并显示它很容易.如果我查看firebug的HTML选项卡,整个div是完全不同的,并且图像被galleria动态填充到这些部分中.不知道该怎么办...请帮忙!
我已在我的应用中为邮政编码实施了自动填充功能.我在Firebug中进行调试,我在控制台中看到操作正在执行,我在结果列表中得到了一个邮政编码列表,但是当我调试时,实际列表没有显示.
这是我的Customers控制器中的操作:
//the autocomplete request sends a parameter 'term' that contains the filter
public ActionResult FindZipCode(string term)
{
string[] zipCodes = customerRepository.FindFilteredZipCodes(term);
//return raw text, one result on each line
return Content(string.Join("\n", zipCodes));
}
Run Code Online (Sandbox Code Playgroud)
这是标记(缩写)
<% using (Html.BeginForm("Create", "Customers")) {%>
<input type="text" value="" name="ZipCodeID" id="ZipCodeID" />
<% } %>
Run Code Online (Sandbox Code Playgroud)
这是我加载脚本的顺序:
<script type="text/javascript" src="/Scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/Scripts/jquery.ui.core.js"></script>
<script type="text/javascript" src="/Scripts/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/Scripts/jquery.ui.position.js"></script>
<script type="text/javascript" src="/Scripts/jquery.ui.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#ZipCodeID").autocomplete({ source: '<%= Url.Action("FindZipCode", "Customers") %>'});
});
</script>
Run Code Online (Sandbox Code Playgroud)
有什么明显我错过了吗?就像我说脚本正在抓取邮政编码列表一样,我测试时它们不会显示在我的页面上.
编辑:我添加了一个图像,显示我在firebug中看到的内容 - …
我正在尝试编写一个正则表达式,它将在字符串中查找width和height属性(它始终是一个html iframe)并替换它具有的值.
我所拥有的是一个字符串,其中###可以是任何值,并且不一定总是3位数.
string iFrame = <iframe width="###" height="###" src="http://www.youtube.com/embed/xxxxxx" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
我想最终得到宽度和高度的设定值:
<iframe width="315" height="215" src="http://www.youtube.com/embed/xxxxxx" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
我试过这个,但对正则表达式不好:
iFrame = Regex.Replace(iFrame, "width=\".*\"", "width=\"315\"");
iFrame = Regex.Replace(iFrame, "height=\".*\"", "height=\"215\"");
Run Code Online (Sandbox Code Playgroud)
结果导致:
<iframe width="315" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
这不是我想要的.有人能帮我吗?