I am working on this little project and what I have to do is to check if the user input is GUID or not.
I have created this Stored Procedure on SQL and it works pretty fine.
ALTER procedure [dbo].[oid_validation] @oid varchar(max)
as
BEGIN TRY
if (TRY_CAST(@oid as uniqueidentifier) IS NOT NULL)
begin
(select select * From Student where oid=@oid)
end
else begin
select 'KO'
end
end TRY
Begin CATCH
print('error')
end CATCH
On my ASP.NET MVC app on the other hand, I want to show the data that this procedure returns, based on whether the input was GUID or not. So my View is:
@foreach (DataRow row in Model.Rows)
{
<div class="ct1">
<h4>Oid: </h4>
<h4>Name: </h4>
<h4>Lastname: </h4>
<h4>Study_Year: </h4>
<h4>Birthday: </h4>
<h4>City:</h4>
</div>
<div class="ct2">
<h4>@row["oid"]</h4>
<h4>@row["Name"]</h4>
<h4>@row["Lastname"]</h4>
<h4>@row["StudyYear"]</h4>
<h4>@row["Birthday"]</h4>
<h4>@row["City"]</h4>
</div>
}
This also works fine. By this the users will see the data they wanted, again *based on whether that input was guid or not. Now what I'm trying to do is manipulate something so if the user enters invalid input, to show some text or redirect somewhere else;
Something like this:
if(userinput!=guid)
{
<h4>Your data is invalid, please check your string!</h4>
}
else
{
//foreach(...)
{
<data1>
@<data1>
}
}