嗨,大家好我有问题,我不明白为什么会发生这种情况.
出于某种原因,我的第二次提交时,我的ajax调用是双重发布.
我有一个包含这个的视图:
@using (Ajax.BeginForm("Create", "BasketPage", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "myDiv",
}))
{
<textarea id="comment" name="comment"> </textarea> <br />
<input type="submit" class="btn btn-blue" value="Comment" />
}
Run Code Online (Sandbox Code Playgroud)
调用的BasketPage控制器操作如下所示:
public PartialViewResult Create(BasketPage currentPage, string comment)
{
Comment newComment = new Comment()
{
Username = User.Identity.Name,
Text = HttpUtility.HtmlEncode(comment),
PageID = currentPage.PageLink.ID
};
commentRepository.Save(newComment);
var model = new BasketListModel(currentPage)
{
CommentsList = commentRepository.GetComments(currentPage.PageLink)
};
return PartialView("_Comment", model);
}
Run Code Online (Sandbox Code Playgroud)
问题场景:
如果我用常规的@ Html.BeginForm替换Ajax.beginform,则只调用一次Save方法.
我错过了什么?
我的方法使用SMTP中继服务器发送电子邮件.
一切正常(电子邮件被发送),除了附件(图像)以某种方式压缩/记录,并且无法从电子邮件中检索.
该方法如下所示:
public static bool SendEmail(HttpPostedFileBase uploadedImage)
{
try
{
var message = new MailMessage() //To/From address
{
Subject = "This is subject."
Body = "This is text."
};
if (uploadedImage != null && uploadedImage.ContentLength > 0)
{
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(uploadedImage.InputStream, uploadedImage.FileName);
message.Attachments.Add(attachment);
}
message.IsBodyHtml = true;
var smtpClient = new SmtpClient();
//SMTP Credentials
smtpClient.Send(message);
return true;
}
catch (Exception ex)
{
//Logg exception
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,正在发送的电子邮件包含图像作为具有正确文件名的附件,尽管它的大小为0字节.
我错过了什么?
我创建了一个触发器,该任务是存储有关触发器事件的信息。例如:“新员工于2014年10月13日添加到表中。
我创建了一个表-Audit-存储所有信息(来自触发器)。
CREATE TABLE [dbo].[Audit](
[id] [int] IDENTITY(1,1) NOT NULL,
[tableName] [nvarchar](255) NOT NULL,
[auditData] [nvarchar](max) NULL,
[userName] [nvarchar](255) NOT NULL,
PRIMARY KEY (id))
Run Code Online (Sandbox Code Playgroud)
但是,我创建的触发器如下所示:
CREATE TRIGGER [dbo].[tr_Actor_ForInsert_Audit]
ON [dbo].[Actor]
FOR INSERT
AS
BEGIN
DECLARE @userName NVARCHAR(255)
DECLARE @tableName NVARCHAR(255) = 'Actor'
DECLARE @name VARCHAR(255)
DECLARE @birthdate DATE
SELECT @userName = SYSTEM_USER
SELECT @name = name FROM inserted
SELECT @birthdate = birthdate FROM inserted
INSERT INTO Audit VALUES (@tableName, 'New ' + LOWER(@tableName) + ' with Name = ' + …Run Code Online (Sandbox Code Playgroud) 我一直在冥思这个错误一段时间,并尝试了网上发现的所有建议,但仍然没有运气.
我正在对控制器的动作进行简单的ajax调用.该应用程序位于EPiServer中,但这似乎是关于在ASP.NET中使用Ajax的一般性问题.
索引视图:
<input id="btnAjax" type="button" value="Favorite" />
<script>
$('#btnAjax').click(function () {
$.ajax({
url: '@Url.Action("SetCookie", "Home")',
contentType: 'application/html; charset=utf-8',
type: 'POST',
dataType: 'html'
})
.success(function (result) {
alert("Success");
})
.error(function (xhr, status) {
alert(status);
})
});
</script>
Run Code Online (Sandbox Code Playgroud)
控制器 - HomeController:
[HttpPost]
public void SetCookie()
{
//Do stuff
}
Run Code Online (Sandbox Code Playgroud)
我做了什么/尝试过:
正确引用jquery.
为操作添加了[WebMethod]属性
在Web.config中添加了一个Http模块(ScriptModule,用于EPiServer)
在引用jquery之后添加了对jquery.unobtrusive-ajax.js的引用.
当我运行webapplication并按下按钮时,Developer工具中的调试器告诉我
这很奇怪,因为在HomeController中有一个名为SetCookie()的动作/方法.并显示警告框"失败",表示至少调用了js函数.
无论是我是盲人还是缺少某些东西,或者还有其他需要做的事情......
欢迎所有建议,非常感谢.
/ ChrisRun
在我的模型中,我想格式化一个double的输出。我正在尝试输出这样的数字:
100000000 as 100.000.000 (仅是一个点分隔符)
但是通过使用这种(货币格式)
[DisplayFormat(DataFormatString = "{0:C}")]
Run Code Online (Sandbox Code Playgroud)
结果=> 424.232.344 kr
我还获得了货币符号(取决于文化,在我的情况下为“ kr”),但我不想要那样。我只想要点分隔符但没有货币。
有什么建议么?
问候所有 EPiServer 专家。
环境:EPiServer 7。
问题描述:
我有一个具有不同属性的 PageType。其中一个属性是 ContentReference。
[CultureSpecific]
[Display(
Name = "Specific documents",
GroupName = SystemTabNames.Content,
Order = 1)]
public virtual ContentReference SpecificDocument { get; set; }
Run Code Online (Sandbox Code Playgroud)
在我看来,我显示一个链接到不同操作的图标,具体取决于属性 SpecificDocument 是否为空。ContentReference 属性应该包含一个文件,例如 PDF。
@model IPageViewModel<SpacePage>
<div class="row">
@if (Model.CurrentPage.SpecificDocument != null)
{
<a class="image" href="#"> </a>
}
else
{
<a class="icon" href="some action if the property is empty"></a>
}
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题:
如果 SpecificDocument 属性不为 null,我如何href到ContentReference 属性中的特定内容?
说明:当用户单击该图标时,它会在窗口中打开特定文档 (PDF) 或下载它。
请记住,我是 EPiServer 开发的新手。
问候,克里斯
asp.net-mvc ×3
ajax ×2
c# ×2
episerver ×2
asp.net ×1
asp.net-ajax ×1
audit ×1
format ×1
forms ×1
href ×1
smtp ×1
sql-server ×1
triggers ×1