我在控制器中有一个动作结果的方法,如果条件失败我有一些条件然后我想发送一个json对象到视图但我无法做到。任何人都可以帮助我。
[HttpPost]
public ActionResult Loginuser(LoginDetails newlogin)
{
LoginDetails objlogin = new LoginDetails();
objlogin.UserEmail = newlogin.UserEmail;
objlogin.UserPassword = newlogin.UserPassword;
try
{
if (ModelState.IsValid)
{
RegisterBAL Regball = new RegisterBAL();
objlogin = Regball.LoginUserBAL(objlogin);
if(objlogin.ResponseCode == "000")
{
if(objlogin.UserRole =="CityHelpdesk")
{
return RedirectToAction("CityHelpdesk", "RoleDashbord");
}
if (objlogin.UserRole == "CityAdmin")
{
return RedirectToAction("CityAdmin", "RoleDashbord");
}
if (objlogin.UserRole == "StateAdmin")
{
return RedirectToAction("StateAdmin", "RoleDashbord");
}
if (objlogin.UserRole == "StateHelpdesk")
{
return RedirectToAction("StateHelpdesk", "RoleDashbord");
}
}
else
{
return json object//// Hear i want to return the json object
}
}
}
catch (Exception)
{
objlogin.ResponseCode = "EXC";
}
}
答案 0 :(得分:2)
您可以通过return Json()
方法
根据您的情况,这将是return Json(objlogin);
请注意,您将把用户名和密码发回客户端。更好地过滤掉您需要的字段并返回新模型