这个例子是同一界面进行2次请求。可以用Ajax回调
界面前台部分代码
<form action="InviteByOtherMail.html" method="post" >
<div class="divshow1" style="color:Red; font-weight:bold">目前读取邮箱通讯录支持如下邮
箱:gmail(Y)、hotmail(Y)、live(Y)、tom(Y)、yahoo(Y)(有点慢)、sina(Y)、163(Y)、sohu(Y)、
tom(Y)<br />
读取后可以发送邮件(完善版本)</div>
<div class="member-info">
<ul>
<li><strong>输入Email地址:</strong><%= Html.TextBoxFor(model =>
model.username, new { @class = "text_input" })%></li>
<li><strong> 输入密码:</strong><%= Html.PasswordFor(model => model.mailpass,
new { @class = "text_input" })%></li>
<li ><input type ="button" value ="导入" onclick="javascript:MailSelect('username','mailpass','nameList','1'); "
/></li>
<li ><strong> 全选</strong> <input type="checkbox" id="all" onclick="selectAll
(this)"/></li>
<li ><strong> 好友 邮件集合: </strong> <div id="nameList" name="nameList"></div></li>
<li ><strong> 要发送邮件的好友邮箱地址:</strong> <input type="text" id="Text1" name="nameList1"/></li>
<li > <strong> 邮件正文:</strong><%= Html.TextBoxFor(model => model.strcontent
, new { @class = "text_input" })%> </li>
<li> <strong> 当前用户: </strong> <%= Html.TextBoxFor(model =>
model.FullName , new { @class = "text_input" })%></li>
<li> <input type="submit" id="btn_submit" name="btn_submit" value="发送邀请
»" action ="Send" /> <input name="returnbutton" type="button" value="返 回"
onclick ="window.location='EspeciallhelList.html'" class="button_input" /> </li>
<li> <% = ViewData["JSAlert"]%> </li>
</ul>
</div>
</form>
2Ajax回调的代码
/*
根据密码,邮箱查联系人 (非msn账号)*/
function MailSelect(thisobj, selobj, changobj,selval){
$.ajax({ type: "post",
url: "ChangeSelectMail.html",
dataType: "json",
data: { "mail": $('#' + thisobj).val(), "pass": $('#' + selobj).val() },
success: function(v_return) {
if (v_return != null || v_return != "") {
$('#' + changobj).html(v_return.rtn);
setTimeout(function() { if (selval != "") $('#' + changobj).val(selval); });
}
}
});
}
后台ctroller关键代码
//回调通过邮箱,密码查出的联系人列表(其它邮箱)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ChangeSelectMail()
{
string mails = StringHelper.GetRequest("mail");//邮箱
string pwd= StringHelper.GetRequest("pass");//密码
return Json(new { rtn = showiFriends(mails,pwd) });
}
//不同邮箱导入联系人邀请
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult InviteByOtherMail(string username, string mailpass, string strcontent, string FullName,string sendmail)
{
MemberInfoModel model2 = MemberInfoModel();
model2.mailpass = mailpass; //邮箱密码
model2.username = username;//发送邮件的地址
model2.strcontent = strcontent;//邮件内容
model2.sendmail = sendmail;
string aa = model2.FullName;//发送请求的当前用户名
ViewData["email"] = "";
aa = FullName;
return View(model2);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InviteByOtherMail(){
string cname = StringHelper.GetRequest("FullName");//当前用户
string users = StringHelper.GetRequest("username");//请求的用户名
string pass = StringHelper.GetRequest("mailpass");//请求的邮件密码
string mailto = Request.Form.Get("nameList1"); //要发送邮件的地址
string[] maillist = mailto.Split(';');
for (int i = 0; i < maillist.Length; i++)
{
inviteFriends.SendConfirmMail(maillist[i].ToString(), titile, lr2);//发邮件
}
return View();
}
IList<Person> list;
//查找好友的联系人邮箱地址(不是MSN)
public string showiFriends(string username, string password)
{
string str = "";
StringBuilder sd = new StringBuilder();
GetAddressStatus status = GetContactPerson.GetAddressByEmail(username, password, null, out list);//得到邮箱登录后的状状态,返回枚举结果
switch (status)
{
case GetAddressStatus.Success:
if (status == GetAddressStatus.Success)
{
foreach (Person p in list)
{
sd.Append(" <table >");
sd.Append("<tr>");
sd.Append("<td>");
sd.Append("选择: <input type='checkbox' onclick= 'selectMe(this)' id='" + p.Email.ToString() + "' value='" + p.Email.ToString() + "' /></td>");
sd.Append(" <td width='20px'> <input type='textbox' id='gg' value='" + p.Email.ToString() + "' /></td>");
sd.Append("</tr>");
sd.Append(" </table >");
}
return sd.ToString();
}
else
{
return "";
}
}
return sd.ToString();
}