Asp.net mvc 3 MVC3视图作为弹出窗口
我想以弹出窗口的形式打开查看 这是我的 控制器Asp.net mvc 3 MVC3视图作为弹出窗口,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我想以弹出窗口的形式打开查看 这是我的 控制器 #region Send Voting Email [HttpGet] [OutputCache(Location = OutputCacheLocation.None)] [Authorize] public ActionResult SendVotingEmail(string CampID) { try { var model = (new Ca
#region Send Voting Email
[HttpGet]
[OutputCache(Location = OutputCacheLocation.None)]
[Authorize]
public ActionResult SendVotingEmail(string CampID)
{
try
{
var model = (new CampManager()).GetCampDetails(CampID);
var user = (Bank.Security.BankMembershipUser)Membership.GetUser();
Models.Camp.EmailModel VotingModel = new Models.Camp.EmailModel();
VotingModel.CampID = CampID;
VotingModel.BankName = user.BankName;
VotingModel.Message = "";
return RedirectToAction("Send", VotingModel);
//(new CampManager()).SendEmail(CampID, user.BankName,"");
//return Content("Email send successfully.");
}
catch(Exception ex)
{
return Content("Sorry, An error occured while sending Voting Email. Please contact Administrator.");
}
}
#endregion
#region Send Voting mail popup
[HttpGet]
public ActionResult Send(Models.Camp.EmailModel model)
{
return View(model);
}
[HttpPost]
public ActionResult Send(Models.Camp.EmailModel model,string CampID)
{
(new CampManager()).SendEmail(model.CampID,model.BankName,model.Message);
return Content("Email send successfully.");
}
#endregion
Sendmail.cshtml
<input type="button" id="ClickMe" name = "ClickMe" value="Send Voting Email" onclick="SendEmail('@Model.CampID');" />
<script type="text/javascript">
$(function () {
$('#ClickMe').click(function () {
window.open('/Camp/Send/', 'mail', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
});
});
function SendEmail(CampID) {
$('#sendEmailProgressBar').css("visibility", "visible");
$.get('/bank/Camp/SendEmail?CampID=' + CampID, function (data) {
$('#sendEmailProgressBar').css("visibility", "collapse");
alert(data);
});
</script>
@model Bank.Models.Camp.EmailModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Send</title>
</head>
<body>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>EmailModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CampID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CampID)
@Html.ValidationMessageFor(model => model.CampID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.BankName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.BankName)
@Html.ValidationMessageFor(model => model.BankName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Message)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
$(函数(){
$('#ClickMe')。单击(函数(){
window.open('/Camp/Send/','mail',height='+(window.screen.height-100)+',width=200,left='+(window.screen.width-250)+',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
});
});
发送电子邮件功能(CampID){
$('#sendmailprogressbar').css(“可见性”、“可见”);
$.get('/bank/Camp/sendmail?CampID='+CampID,函数(数据){
$('#sendmailprogressbar').css(“可见性”、“折叠”);
警报(数据);
});
Send.cshtml
<input type="button" id="ClickMe" name = "ClickMe" value="Send Voting Email" onclick="SendEmail('@Model.CampID');" />
<script type="text/javascript">
$(function () {
$('#ClickMe').click(function () {
window.open('/Camp/Send/', 'mail', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
});
});
function SendEmail(CampID) {
$('#sendEmailProgressBar').css("visibility", "visible");
$.get('/bank/Camp/SendEmail?CampID=' + CampID, function (data) {
$('#sendEmailProgressBar').css("visibility", "collapse");
alert(data);
});
</script>
@model Bank.Models.Camp.EmailModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Send</title>
</head>
<body>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>EmailModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CampID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CampID)
@Html.ValidationMessageFor(model => model.CampID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.BankName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.BankName)
@Html.ValidationMessageFor(model => model.BankName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Message)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@model Bank.Models.Camp.EmailModel
@{
布局=空;
}
发送
@使用(Html.BeginForm()){
@Html.ValidationSummary(true)
电子邮件模型
@LabelFor(model=>model.CampID)
@EditorFor(model=>model.CampID)
@Html.ValidationMessageFor(model=>model.CampID)
@LabelFor(model=>model.BankName)
@EditorFor(model=>model.BankName)
@Html.ValidationMessageFor(model=>model.BankName)
@LabelFor(model=>model.Message)
@EditorFor(model=>model.Message)
@Html.ValidationMessageFor(model=>model.Message)
}
@ActionLink(“返回列表”、“索引”)
当我点击SendMail.cshtml的ClickMe按钮时,我想打开弹出窗口。当我点击此按钮时,弹出窗口打开,但它显示Send.cshtml视图的代码。我不知道为什么会发生这种情况。我打开弹出窗口的代码是否有任何更改
试试这个
<script type="text/javascript">
function OpenWindow(query, w, h, scroll) {
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
if (scroll) winprops += ',scrollbars=1';
var f = window.open(query, "_blank", winprops);
}
$(function () {
$('#ClickMe').click(function () {
OpenWindow('@Url.Action("Send","Camp")', width, height, true);
});
});
</script>
检查问题。第二个答案正是您想要的。当您提交表单时,它将打开一个新窗口。您甚至可以在将表单提交到新窗口之前自定义窗口设置。带有id的标记ClickMe是提交按钮吗?您希望在弹出窗口中打开哪个视图?@Shivkumar I want Send.cshtml作为弹出窗口打开我有测试没有问题。@BehnamEsmaili你能发布你的代码吗?你用另一个视图测试过另一个操作吗?我在一个示例项目中测试过它,效果很好,但在我的原始项目中,我使用了按钮的点击事件。所以我想这就是为什么我没有得到我的弹出窗口