简体   繁体   English

如何从MVC4剃须刀中的公共类重定向URL

[英]How to redirect url from public class in mvc4 razor

I want to redirect page after sending the mail to active page. 将邮件发送到活动页面后,我想重定向页面。 I have created a Model SendMail and Controller 我创建了一个模型SendMail和控制器

In Model SendMail.cs I'm fetching data: 在模型SendMail.cs中,我正在获取数据:

public class SendMail
{
  public string Name { get; set; }
  public string Email { get; set; }
  public string Comment { get; set; }
}

In Controller SendMail: 在控制器的SendMail中:

 [HttpGet]
 public ActionResult SendMail()
 {
   return View();
 }
 [HttpPost]
 public string SendMail(SendMail SendMail)
 {
  if (!String.IsNullOrEmpty(SendMail.Name) && !String.IsNullOrEmpty(SendMail.Email) && !String.IsNullOrEmpty(SendMail.Comment))
  {
    //Sending Mail SMPT Setting                    
    return Url;
  }
  else
  return Url;
  }

It works Perfectly but I don't understand How can I redirect Active Url in public string SendMail class after Sending Mail. 它工作正常,但是我不明白如何在发送邮件后如何在公共字符串SendMail类中重定向Active Url。

before sending mail before sending mail after Sending mail after sending mail 发送邮件之前发送邮件之前发送邮件之后发送邮件之后

Thank You 谢谢

Can you try this? 你可以试试这个吗?

[HttpPost]
 public ActionResult SendMail(SendMail SendMail)
 {
  if (...)
  {
    //Sending Mail SMPT Setting    
    return RedirectToRoute(URL);
  }
  else
  return RedirectToRoute(URL);
}

I think you need to change string by ActionResult to be able to redirect. 我认为您需要通过ActionResult更改字符串才能重定向。 I hope it will be helpfull. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM