我在我的jquery中使用Html.ActionLink但是当我输入我的动作名称时出现错误,请检查我的更新.
我为什么要这个?我真的需要在这里使用ActionLink.
这是jquery代码:
result.forEach(function (goalcard) {
$("#GoalcardSearchResult tbody").append(
$('<tr/>', {
click: function () {
id = goalcard.Id;
var url = '@Url.Action("AnswerForm", "AnswerNKI", new { id = "__id__"})';
window.location.href = url.replace('__id__', id);
},
// steg Create a row for each result
html: "<td>" + goalcard.Name +
"</td><td>" + goalcard.Customer +
"</td><td>" + goalcard.PlannedDate +
"</td><td>" + goalcard.CompletedDate +
"</td><td>" + '@(Html.ActionLink("Ändra", "Edit","Admin")) | @(Html.ActionLink("Skapa Mall", "Inactive","Admin", new { @class = "deleteLink" })) | @(Html.ActionLink("Genomför","AnswerForm","AnswerNKI"))' + "</td>"
}));
});
$('#GoalcardSearchResult tbody').trigger("update");
$("#GoalcardSearchResult").tablesorter({ …Run Code Online (Sandbox Code Playgroud) 在我开始之前是问题所在.它应该是这样的:
BjörnNilsson反而显示奇怪的特殊字符,所有具有字符Å,Ä和Ö的值都变成这样.

我使用具有所有值的XML格式的API填充我的DDL,我们也使用Linq2Rest.
这个过程看起来如何
private readonly RestContext<ADConsultants> restContext;
public ConsultantContext(Uri uri, Format format)
{
restContext = new RestContext<ADConsultants>(GetRestClient(uri, format), GetSerializerFactory(format));
}
public enum Format
{
Pox,
Json
}
private static readonly IEnumerable<Type> knownTypes = new[] {typeof (ADConsultants)};
public static IRestClient GetRestClient(Uri uri, Format format)
{
switch (format)
{
case Format.Pox:
return new XmlRestClient(uri);
case Format.Json:
return new JsonRestClient(uri);
default:
throw new NotImplementedException();
}
}
private static ISerializerFactory GetSerializerFactory(Format format)
{
switch (format)
{
case Format.Pox:
return new XmlSerializerFactory(knownTypes);
case Format.Json: …Run Code Online (Sandbox Code Playgroud) 我最终完成了我的ASP.NET Webapplicaton,我的解决方案包含三个项目:webapplication本身,WCF和Classlibrary.但我想重构它来改变类名,项目名称等.我怎么能以平滑的方式做到这一点,所以一切都不会搞砸,比如命名空间等等.我也有Resharper但我是新手.
当我重命名我的Project文件和.csproj等时,我仍然遇到命名空间问题,新的命名空间不起作用,它要求旧命名空间.
提前致谢!
我有一个我觉得非常沉重的动作结果,所以我想知道如何优化它以便它获得更好的性能.此Web应用程序将同时由+ 100,000个用户使用.
现在我的Actionresult做了以下事情:
每次用户访问视图时,此4个函数都会触发.这就是为什么我认为这个Actionresult非常糟糕.
如何将以下内容添加到我的Actionresults中?
添加计时器来检索XML文件并将xml数据填充到DB,就像每10分钟一样,因此每次用户访问视图时都不会触发.每次用户访问站点时,唯一需要触发的功能是viewmodel绑定并返回模型.我怎么能做到这一点?
注意:
这是我的行动结果:
public ActionResult Index()
{
//Get data from xml url (This is the code that shuld not run everytime a user visits the view)
var url = "http://www.interneturl.com/file.xml";
XNamespace dcM = "http://search.yahoo.com/mrss/";
var xdoc = XDocument.Load(url);
var items = xdoc.Descendants("item")
.Select(item => new
{
Title = item.Element("title").Value,
Description = item.Element("description").Value,
Link = item.Element("link").Value,
PubDate = item.Element("pubDate").Value,
MyImage = (string)item.Elements(dcM + "thumbnail")
.Where(i => i.Attribute("width").Value …Run Code Online (Sandbox Code Playgroud) 我首先在我的项目中使用MVC-Viewmodel,EF模型.
我有一个foreach循环,在我的视图中生成4个表.我希望生成的每个表都获得一个唯一的ID.我想我必须在我的ViewModel中执行此操作.
感谢任何帮助我所知道的是我需要在foreach循环中声明这样的内容:
<table id="RandomID_@("MyRandomProperty)">
Run Code Online (Sandbox Code Playgroud)
可能是这样的属性:
public random MyRandomProperty {get;set;}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我在我的MVC项目中使用Nlog
我想要实现的是在我的控制器中执行操作方法时记录消息.并且日志消息应出现在txt文件中.但我似乎无法让它发挥作用
我已将Nlog安装到我的参考资料中.
我有Nlog.Config,配置如下:
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file"
xsi:type="File"
layout="${longdate} ${logger} ${message}"
fileName="${basedir}/logs/logfile.txt"
keepFileOpen="false"
encoding="iso-8859-2" />
</targets>
<rules>
<logger name="*"
minlevel="Debug"
writeTo="file" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中的POST动作方法中,我有以下代码:
[HttpPost]
public ActionResult Edit(int id, CreateNKIphase1ViewModel model)
{
Logger logger = LogManager.GetCurrentClassLogger();
logger.Info("Test message");
//code....
}
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到txt文件?
为什么这不起作用:S
我有一个字符串变量,看起来像这样:
ÅretsupplagaavStorsjöcupen,en fotbollsturneringiÖstersundförungdomar,fick en tristavrundningnäranhängare能到这里旅游了解更多信息来自世界各地的旅游景点.
当我的javascript被执行时,它将字符串转换为:
ÅretsupplagaavStorsjöcupen,en fotbollsturneringiÖstersundförungdomar,fick en tristavrundningnäruhängaretindett norskt pojklag ...
如果你看到三个"......",我就不想拥有一个空间.
我希望它是:
pojklag ...
我的javascript看起来像这样:
function TrimLength(text, maxLength) {
text = $.trim(text);
if (text.length > maxLength) {
text = text.substring(0, maxLength - ellipsis.length)
return text.substring(0, text.lastIndexOf(" ")) + ellipsis;
}
else
return text;
}
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function () {
$(".text").each(function () {
var text = $(this).text();
$(this).text(TrimLength(text, 150));
});
Run Code Online (Sandbox Code Playgroud)
如何确保空间被移除?
任何形式的帮助表示赞赏.
当用户创建消息时,有一个多箱,这个多箱连接到一个设计面板,让用户可以更改字体,颜色,大小等.当提交消息时,如果用户改变颜色,消息将显示为带有html标签的消息,字体大小等.
注意:我需要设计面板,我知道可以删除它,但事实并非如此:)
这是一个Sharepoint标准,我唯一的解决方案是使用javascript在显示时剥离这些标记.用户应该只能插入链接,图像和添加换行符.
这意味着除了和标签外<a></a>,所有的html标签都应该被剥离.<img><br>
同样重要的是<img>标签内部的属性不会被删除.它可以像这样显示:
<img src="/image/Penguins.jpg" alt="Penguins.jpg" style="margin:5px;width:331px;">
Run Code Online (Sandbox Code Playgroud)
我怎样才能通过javascript实现这一目标?
我曾经使用过以下代码隐藏的C#代码,它完美地工作但它会剥离除标签之外的所有html标签<br>.
public string Strip(string text)
{
return Regex.Replace(text, @"<(?!br[\x20/>])[^<>]+>", string.Empty);
}
Run Code Online (Sandbox Code Playgroud)
任何形式的帮助都很受欢迎
我正在构建一个自定义的痕迹,我想要每个LinkButton唯一的commandArgument url.
我有一个通用的字符串变量,它是一个url.每个子网站的名称可以是不同的,并且尽可能地不限制hierchy.
String变量可能如下所示:
http://site/org/content/Change/Book/process/item
Run Code Online (Sandbox Code Playgroud)
我想要做的是拆分字符串变量并将其添加到数组,所以它看起来像这样:
http://site/org
http://site/org/content/
http://site/org/content/Change/
http://site/org/content/Change/Book/
http://site/org/content/Change/Book/process/
http://site/org/content/Change/Book/process/item
Run Code Online (Sandbox Code Playgroud)
我试过以下代码:
private void AddBreadCrumb(SPWeb web)
{
var webUrl = web.Url;
var linkList = new List<string>(webUrl.Split('/'));
// etc..
}
Run Code Online (Sandbox Code Playgroud)
但它并不像我希望它那样做.
适用任何形式的帮助
我首先使用EF模型并在MVC中使用viewmodels,我遇到此错误的问题:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[NKI3.Models.Question]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[NKI3.ViewModels.IndexCreateViewModel]'.
Run Code Online (Sandbox Code Playgroud)
这是我的viewmodel:
public class IndexCreateViewModel
{
public string QuestionText { get; set; }
public string Sname { get; set; }
public string Cname {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
这是我在我的控制器中的动作:
public ActionResult Index()
{
var Q = db.Question.Include(a => a.SubjectType).Include(a => a.CoreValue);
return View(Q.ToList());
}
Run Code Online (Sandbox Code Playgroud)
这是我的强类型视图:
@model IEnumerable<NKI3.ViewModels.IndexCreateViewModel>
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
QuestionText
</th>
<th>
Sname
</th>
<th> …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×6
c# ×6
asp.net ×2
javascript ×2
jquery ×2
razor ×2
actionresult ×1
arrays ×1
html ×1
json ×1
json.net ×1
logging ×1
mvvm ×1
nlog ×1
performance ×1
refactoring ×1
rename ×1
resharper ×1
split ×1
string ×1
strip ×1
xml ×1