【发布时间】:2017-05-20 14:58:09
【问题描述】:
点击按钮:
$("#newSave").click(function () {
AddNewAccount();
});
我正在调用函数:
function AddNewAccount() {
$.post("/RxCard/AddAccount",
{
NewAccountName: $("#newAccountName").val(),
NewAccountAddress: $("#newAccountAddress").val(),
NewAccountCity: $("#newAccountCity").val(),
NewAccountState: $("#newAccountState").val(),
NewAccountZip: $("#newAccountZip").val(),
NewAccountArea: $("#newArea").val(),
NewAccountPrefix: $("#newPrefix").val(),
NewAccountSuffix:$("#newSuffix").val()
}, function (errorMsg) {
if (errorMsg.length > 0) {
$('div#divSearchList').empty();
$('div#divSearchList').html(errorMsg);
}
else {
loadAccount(accountId, false);
}
});
$("body").css("cursor", "default").delay(1000);
}
从那里将数据传递到控制器操作中:
public ActionResult AddAccount(string NewAccountName, string NewAccountAddress, string NewAccountCity, string NewAccountState, string NewAccountZip, string NewAccountArea, string NewAccountPrefix, string NewAccountSuffix)
{
DuplicatesPage model = GetDups(NewAccountName, NewAccountAddress, NewAccountCity, NewAccountState, NewAccountZip, NewAccountArea, NewAccountPrefix, NewAccountSuffix);
return RedirectToAction("DuplicatePage", model);
}
为了从以下位置生成模型(用于我试图显示的视图):
private DuplicatesPage GetDups(string NewAccountName, string NewAccountAddress, string NewAccountCity, string NewAccountState, string NewAccountZip, string NewAccountArea, string NewAccountPrefix, string NewAccountSuffix)
{
DuplicatesPage model = new DuplicatesPage();
duplicates results = new duplicates();
var phone = NewAccountPrefix.ToString() + NewAccountSuffix.ToString();
var datenow = DateTime.Now;
var firstofmonth = new DateTime(datenow.Year, datenow.Month, 1);
OdbcCommand cmd1 = new OdbcCommand();
cmd1.CommandText = "{call dbo.Maint_AddClinic(?,?,?,?,?,?,?,?,?)}";
cmd1.Parameters.AddWithValue("@Name", NewAccountName);
cmd1.Parameters.AddWithValue("@Address", NewAccountAddress);
cmd1.Parameters.AddWithValue("@City", NewAccountCity);
cmd1.Parameters.AddWithValue("@State", NewAccountState);
cmd1.Parameters.AddWithValue("@Zip", NewAccountZip);
cmd1.Parameters.AddWithValue("@AreaCode", NewAccountArea);
cmd1.Parameters.AddWithValue("@PhoneNumber", phone);
cmd1.Parameters.AddWithValue("@StartDate", firstofmonth);
cmd1.Parameters.AddWithValue("@AccountTypeID", 2);
cmd1.Parameters.AddWithValue("@IgnoreDupAddress", 1);
DataTable dt = GetData(cmd1);
foreach (DataRow row in dt.Rows)
{
Pharmacy pharmacy = new Pharmacy();
pharmacy.AccountName = row["AccountName"].ToString();
pharmacy.Address = row["Address"].ToString();
pharmacy.City = row["City"].ToString();
pharmacy.ZipCode = row["ZipCode"].ToString();
results.Pharmacies.Add(pharmacy);
}
results.Count = dt.Rows.Count;
model.DupResults = results;
return model;
}
结束于:
public ActionResult DuplicatePage()
{
return View("Duplicates");
}
问题是我没有重定向到视图Duplicates。我只是停留在同一页面上。问题可能很明显,但我似乎无法找到它。我在单击按钮后调用AddNewAccount 后尝试重定向,但当时没有生成我的Duplicates 模型。
【问题讨论】:
标签: c# asp.net-mvc