【问题标题】:How to clear input text record when i submit to other page and previous page提交到其他页面和上一页时如何清除输入文本记录
【发布时间】:2020-12-02 08:28:40
【问题描述】:

我想在提交和以前的页面时自动清除记录。

model
public class UserClass
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Required(ErrorMessage = "Entry ID")]
    public int ID { get; set; }
    [Required(ErrorMessage = "Entry Name")]
    public string Name { get; set; }
}
控制器
private readonly ApplicationUserClass _auc;
public abcController(ApplicationUserClass auc)
{
    _auc = auc;
}

public IActionResult Index()
{
    return View();
}

public IActionResult Create()
{
    return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(UserClass uc)
{
    _auc.Add(uc);
    _auc.SaveChanges();
    return View();
}

我看到了很多例子,但没有用。谁能给点建议?

【问题讨论】:

    标签: c .net asp.net-core .net-core


    【解决方案1】:

    您可以尝试在post方法中添加ModelState.Clear();

    [HttpPost]
    [ValidateAntiForgeryToken]
    public IActionResult Create(UserClass uc)
    {
        ModelState.Clear();
        return View();
    }
    

    【讨论】:

    • 嗨,mj1313,谢谢你的帮助。这对我很有用。非常感谢!
    • 嗨@ericso,很高兴你的工作,请accept it as answer,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 2012-06-17
    • 2012-10-26
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多