Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How can I use validation from HomeController

$
0
0

Hi

How can I use validation from HomeController with post method. throw new Exception("This ip is not valid !!!",);

<div class="form-group">
<label asp-for="Ip" class="col-md-2 control-label"></label>
<div class="col-md-4">
<input asp-for="Ip" class="form-control" asp-is-disabled="true"
value="@HttpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString()"/>
<span asp-validation-for="Ip" class="text-danger"></span>
</div>
</div>

[HttpPost]
        public ActionResult Register(Kullanicilar kullanicilar)
        {
            if (kullanicilar.IP == "0.0.0.0")

            {
                throw new Exception("This ip is not valid !!!",);
                return View();
            }
            else
            {

                if (ModelState.IsValid)
                {
                    _context.Kullanicilar.Add(kullanicilar);
                    _context.SaveChanges();

                    ModelState.Clear();
                    ViewBag.Message = kullanicilar.Adi + " " + kullanicilar.Soyadi + " kaydınız tamamlandı.";
                }
                return View();
            }
        }

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>