【发布时间】:2021-09-29 11:57:46
【问题描述】:
我正在做这个小项目,我要做的是检查用户输入是否为 GUID。
我已经在 SQL 上创建了这个存储过程,它工作得很好。
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
另一方面,在我的 ASP.NET MVC 应用程序中,我想根据输入是否为 GUID 来显示此过程返回的数据。 所以我的观点是:
@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>
}
这也很好用。这样,用户将再次看到他们想要的数据,*基于该输入是否为 guid。 现在我想做的是操作一些东西,所以如果用户输入无效的输入,显示一些文本或重定向到其他地方;
类似这样的:
if(userinput!=guid)
{
<h4>Your data is invalid, please check your string!</h4>
}
else
{
//foreach(...)
{
<data1>
@<data1>
}
}
【问题讨论】:
-
您的问题究竟是什么?你被什么困住了?
-
嗨,我坚持认为 if(userinput is not Guid) { show something} else { read the data}。
-
您需要帮助的部分似乎没有涉及 SQL Server?
-
如果
@oid意味着包含uniqueidentifier,为什么将其定义为20 亿个字符串?
标签: sql asp.net sql-server asp.net-mvc model-view-controller