开发者

onvalidate in mvc2

开发者 https://www.devze.com 2023-02-08 06:05 出处:网络
How do I implement the OnV开发者_运维百科alidate method in mvc2? I\'m reading an article which shows onvalidate method but I can\'t find in visual studio 2008?I haven\'t seen an OnValidate() method in

How do I implement the OnV开发者_运维百科alidate method in mvc2? I'm reading an article which shows onvalidate method but I can't find in visual studio 2008?


I haven't seen an OnValidate() method in ASP.NET MVC. You may have seen a validation mechanism in LINQ-to-SQL.

In ASP.NET MVC, I'll usually check validation like so:

    public ActionResult Update(SomeModel viewModel)
    {
        if (!ModelState.IsValid)
            return View("Edit", viewModel);

        // some update code...
        PutTempMessage("data updated.");

        return View("Edit", viewModel);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消