我目前有以下代码,旨在与用户核实他们是否确定要在一个月内发布所有事件:
@{
var message = "This publish all events in" + MVC.Events.PublishMonthParams.month.ToString();
}
@using (Html.BeginForm(MVC.Events.PublishMonth(), FormMethod.Post, new { id = "publish-month" onsubmit = "return confirm('Are you sure?')" }))
{
@Html.Hidden(MVC.Events.PublishMonthParams.month, DateTime.Now, new { id = "month" })
@Html.SubmitButton(Strings.PublishAll)
}
但我希望能够显示我的“消息”变量来代替字符串“你确定吗?”。但是,我正在努力让 cshtml 识别变量。我试过这样的事情:
onsubmit = "return confirm(message)"
onsubmit = "return confirm('message')"
onsubmit = "return confirm(@message)"
但没有运气。对最好的方法有什么建议吗?