【发布时间】:2015-10-14 02:15:07
【问题描述】:
我的 .cshtml 页面上有一个复选框,当它被选中时,我希望它不发送电子邮件给用户。下面是我必须将布尔值从 .cshtml 页面传输到 .cs 邮件程序代码的各个代码页面,但在某处值未传输。请帮忙。
在 View.cshtml 中,我将复选框放入:
<input class="checkbox_priority" id="no_emails" name="no_emails" type="checkbox" value="true" title="This only applies to the 'Complete' button"/>Do not send e-mail to requestor.
在 Notification.cs 我获取/设置值:
public virtual Boolean no_emails { get; set; } //Used to not send an e-mail to the creator of a request.
最后我将 IF 语句放入 RequestService.cs 上的邮件程序代码中:
[Spring.Transaction.Interceptor.Transaction]
public int Create(int requestId, Policy.Models.Review newReview)
{
Policy.Models.Request request;
Policy.Models.Review review;
request = RequestDao.Get(requestId);
newReview.Id = ReviewDao.Save(newReview);
//Refresh review object
review = ReviewDao.Get(newReview.Id);
request.Review = review;
//Associate review to request
RequestDao.Update(request);
//Notify request's author of a response
string message = "The response to your <a href=\"{0}\">request</a> has been started";
if (!review.Status.IsActive && !no_emails)
message = "The response to your <a href=\"{0}\">request</a> has been completed";
Helpers.Notifier.CreateNotification(request.Author, request, string.Format(message, Helpers.Link.RequestLink(request.Id)));
return newReview.Id;
}
CreateNotification 在名为 Notifier.cs 的单独文件中定义
public static void CreateNotification(IList<Policy.Models.User> recipients, Policy.Models.AAuditable subject, string message)
{
if (recipients != null && recipients.Count > 0)
{
for (int i = 0; i < recipients.Count; ++i)
{
CreateNotification(recipients[i], subject, message);
}
}
}
public static Policy.Models.Notification CreateNotification(Policy.Models.User recipient, Policy.Models.AAuditable subject, string message)
{
Policy.Models.Notification note = new Policy.Models.Notification();
note.Description = message;
note.IsRead = false;
note.User = recipient;
但是,它表示 no_emails 在当前上下文中不存在。如何让代码识别 no_emails 具有来自 .cshtml 页面的布尔值?
【问题讨论】:
-
尝试将复选框名称更改为“no_emails”
-
我假设您的意思是在
if (!review.Status.IsActive && !no_emails)行中? - 您在哪里将no_emails的值传递给该方法?它是Notification类的属性,并且在方法中没有任何地方引用与该类相关的任何内容 - 您拥有的唯一模型是Review
标签: c# html asp.net-mvc razor checkbox