在我的MVC5项目中,我想在局部视图中创建一个菜单.此菜单是动态的,因为它是根据我的数据库中的内容构建的.因此,我有一个控制器负责创建我的菜单并将菜单模型返回到我的局部视图:
public PartialViewResult GetMenu()
{
MenuStructuredModel menuStructuredModel = menuBusiness.GetStructuredMenu();
return PartialView("~/Views/Shared/MenuPartial", menuStructuredModel);
}
Run Code Online (Sandbox Code Playgroud)
在我称为MenuPartial的局部视图中,我想使用razor迭代我的菜单项,例如:
@model MyApp.Models.Menu.MenuStructuredModel
<div class="list-group panel">
@foreach (var category in Model.ViewTypes[0].Categories)
{
<a href="#" class="list-group-item lg-green" data-parent="#MainMenu">@category.ShownName</a>
}
</div>
Run Code Online (Sandbox Code Playgroud)
现在问题是我插入局部视图的视图.如果在视图中我只是这样做:
@Html.Partial("MenuPartial")
Run Code Online (Sandbox Code Playgroud)
它不会调用控制器来首先使用数据填充模型.我想要的是让控制器返回部分.但我不知道如何从视图中做到这一点.在伪代码中我想做的事情如下:
@Html.RenderPartialFromController("/MyController/GetMenu")
Run Code Online (Sandbox Code Playgroud) 我有一个容器,我想使用引导网格分成两个水平行.
顶行应占据高度的80%,其余部分占底部.
<div class="container-fluid">
<div class="row" style="height:80%">
<div class="col-xs-12">This should take up 80% of the height</div>
</div>
<div class="row">
<div class="col-xs-12">This should take up the remaining 20% of the height</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试将高度:80%作为内联样式添加到第一行,但它没有任何效果.
我在这里错过了什么?
我正在使用 UnitOfWork 模式来抽象我的 Asp.Net 应用程序中的数据库访问。基本上我遵循此处描述的 UnitOfWork 模式方法:
https://chsakell.com/2015/02/15/asp-net-mvc-solution-architecture-best-practices/
但是,我很难理解,我将如何获得新添加项目的 ID。就像我想向我的客户存储库添加新客户一样,我将如何获得客户 ID?问题是Add和Commit是解耦的,直到Commit之后才知道Id。
有没有办法使用 UnitOfWork 模式获取添加项的 id?
我有这个C#示例,它将从整数数组创建奇数和偶数的字典:
int[] values = new int[]
{
1,
2,
3,
5,
7
};
Dictionary<int, string> dictionary =
values.ToDictionary(key => key, val => (val % 2 == 1) ? "Odd" : "Even");
// Display all keys and values.
foreach (KeyValuePair<int, string> pair in dictionary)
{
Console.WriteLine(pair);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
[1, Odd]
[2, Even]
[3, Odd]
[5, Odd]
[7, Odd]
Run Code Online (Sandbox Code Playgroud)
我希望在F#中使用ToDictionary类似地执行此操作,并且到目前为止这样做:
let values = [| 1; 2; 3; 5; 7 |]
let dictionary = values.ToDictionary( ??? )
// Display all keys and values. …Run Code Online (Sandbox Code Playgroud) 我在C#中有这个列表:
List<string> words = new List<string> { "how", "are", "you" };
Run Code Online (Sandbox Code Playgroud)
我可以轻松地打印列表的内容:
foreach(string word in words)
Debug.WriteLine(word);
Run Code Online (Sandbox Code Playgroud)
现在我想在F#中做同样的事情(我从这里了解到a List<T>类似于ResizeArray):
let words = ResizeArray<string>()
words.Add("how")
words.Add("are")
words.Add("you")
for word in words do
Debug.WriteLine(sprintf "%s" word)
Run Code Online (Sandbox Code Playgroud)
现在的问题是,在for循环中word变为null.我在这做错了什么?
编辑:这是完整的代码.我按照建议把它改成了printf.不幸的是,当在for循环中时,我仍然会得到null:
let myFunction =
let words = ResizeArray<string>()
words.Add("how")
words.Add("are")
words.Add("you")
for word in words do
printf "%s" word // <-- word becomes null
words
[<EntryPoint>]
let main argv =
ignore myFunction
0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud) 我有这段代码片段,它创建了一个匿名类型元素数组,其中包含Name和FirstLetter属性:
string[] arr = { "Dennis", "Leo", "Paul" };
var myRes = arr.Select(a => new { Name = a, FirstLetter = a[0] });
Run Code Online (Sandbox Code Playgroud)
我想在F#中做同样的事情.我试过了:
let names = [| "Dennis"; "Leo"; "Paul" |]
let myRes = names.Select(fun a -> {Name = a; FirstLetter = a[0]} )
Run Code Online (Sandbox Code Playgroud)
但这不编译.它说:
未定义记录标签"名称".
如何让这条线在F#中工作?
在我的Angular 2 Web应用程序中,我想更改浏览器中的url页面.例如,我想改变它:
至
它不能重定向,不能加载页面,浏览器历史记录必须反映页面更改.
可以这样做吗?
我想使用web.config将我的asp.net网站上的所有请求重定向到带有非www的https://。那是:
http://
http://www
https://www
Run Code Online (Sandbox Code Playgroud)
应该都去
https://
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的web.config文件如下:
<system.webServer>
...
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
上面的代码片段负责重定向这两个代码:
http://
http://www
Run Code Online (Sandbox Code Playgroud)
但是我错过了最后一个,那就是:
https://www ---> https://
Run Code Online (Sandbox Code Playgroud)
怎么做?
我在C#中有这个代码示例,它从数组输出索引和值:
static void Sample_Select_Lambda_Indexed()
{
string[] arr = { "my", "three", "words" };
var res = arr.Select((a, i) => new
{
Index = i,
Val = a
});
foreach(var element in res)
Console.WriteLine(String.Format("{0}: {1}", element.Index, element.Val));
}
Run Code Online (Sandbox Code Playgroud)
输出是:
0: my
1: three
2: words
Run Code Online (Sandbox Code Playgroud)
我想在F#中进行类似的查询,并且像这样开始:
let arr = [|"my"; "three"; "words"|]
let res = query {
for a in arr do
// ???
}
Run Code Online (Sandbox Code Playgroud)
我该如何完成这个LINQ查询?
我的Angular 2组件类中有一个名为myArray的数组:
@Component({
templateUrl: 'my.component.html'
})
export class MyComponent {
private myArray: Array<string>;
...
}
Run Code Online (Sandbox Code Playgroud)
在my.component.html中,我有一个输入元素:
<input placeholder='write some tags' value=''>
Run Code Online (Sandbox Code Playgroud)
我想要的是将myArray的字符串元素插入到输入元素的value属性中。字符串应以逗号分隔。就像是:
<input placeholder='write some tags' value='apple, orange, banana'>
Run Code Online (Sandbox Code Playgroud)
我试过了:
<input name='user-tag' placeholder='write some tags' value='*ngFor="let e of myArray"{{e}}'>
Run Code Online (Sandbox Code Playgroud)
但这产生了一个错误。
我怎样才能做到这一点?
c# ×5
f# ×4
asp.net ×3
linq ×3
angular ×2
asp.net-mvc ×2
typescript ×2
.net ×1
https ×1
iis ×1
javascript ×1
jquery ×1
razor ×1
unit-of-work ×1
web-config ×1