Hello,
I am creating a test website for practice. The homepage looks like this -
On clicking test The view is
I want that when I click ID, a message should be displayed underneath the text box telling if the id is valid or invalid. Im using MVC architecture and connecting to database using ado.net.
I am able to get my invalid/valid message correctly but on getting exception in the return view code below saying cant find the view TestSite.
How can I return the same view as above with the message?
This is my cshtml page
I am creating a test website for practice. The homepage looks like this -
On clicking test The view is
I want that when I click ID, a message should be displayed underneath the text box telling if the id is valid or invalid. Im using MVC architecture and connecting to database using ado.net.
I am able to get my invalid/valid message correctly but on getting exception in the return view code below saying cant find the view TestSite.
C#:
public IActionResult TestSite(Test obj)
{
try
{
if (ModelState.IsValid)
{
DataAccess site = new DataAccess();
if (site.checkSite(obj))
{
ViewBag.Message = "Site Id is valid";
}
else
ViewBag.Message = "Site Id is invalid";
}
return View();
}
catch
{
return View();
}
}
How can I return the same view as above with the message?
This is my cshtml page
C#:
@model PracticeWebsite.Models.Test
<h1>Test</h1>
@using (Html.BeginForm("TestSite", "Home", FormMethod.Post))
{
@Html.TextBoxFor(model => model.sID)
@Html.ValidationMessageFor(model => model.sID)
<button type="submit">Enter ID</button>
<div class="form-group">
<div class="col-md-offset-2 col-md-10" style="color:green">
@ViewBag.Message
</div>
</div>
}