我在MVC 4 Web开发新的和我创建一个控制面板返回相同的形式。我已经开发了一个添加用户页面并成功地在数据库中提交信息。 但提交后,当我按回按钮它会显示以前的形式。 我使用提交表单后将页面重定向到同一页面。 这里是重定向MVC 4网站返回新闻与旧值
public ActionResult AdminPanel(RegisterUserModel user)
{
if (ModelState.IsValid) // Check the model state for any validation errors
{
if (user.AddUserToDB(user.username, user.password, user.fullName,user.contactNo,user.COAId)) // Calls the Login class checkUser() for existence of the user in the database.
{
TempData["SuccessMessage"] = "User Added Sucessfully!";
ModelState.Clear();
return Redirect("AdminPanel");
}
else
{
ViewBag.SuccessMessage = "User Not Added";
return View();
}
}
SelectList clientsList = GetClinetList();
ViewBag.clientsList = clientsList;
return View(); // Return the same view with validation errors.
}
我已经尝试了许多例子,但发行不解决又那么好心给我suggesstions
我不认为任何人能回答这个问题没有得到更多的细节(代码)。也许给我们一个简约的例子。 – Chris311
我已经加了我actionMethod –