Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将信息发送到C类以在cshtml中进行验证_C#_Razor_Input_Submit - Fatal编程技术网

C# 将信息发送到C类以在cshtml中进行验证

C# 将信息发送到C类以在cshtml中进行验证,c#,razor,input,submit,C#,Razor,Input,Submit,如何创建对C类的调用,以验证用户名和密码是否正确,然后将结果返回到此页面 @{ Page.Title = "Login"; Layout = "~/_Layout_Main.cshtml"; } <div id="Login_Wrapper"> <p> Brugernavn/Email: </p> <input type="text" name="brugernavn" id="brugerna

如何创建对C类的调用,以验证用户名和密码是否正确,然后将结果返回到此页面

@{
    Page.Title = "Login";
    Layout = "~/_Layout_Main.cshtml";
}


<div id="Login_Wrapper">
    <p>
        Brugernavn/Email:
    </p>
    <input type="text" name="brugernavn" id="brugernavn" placeholder="Brugernavn/email" />

    <p>
        Password:
    </p>
    <input type="text" name="password" id="password" placeholder="Password" />

    <button type="submit" class="btn">Submit</button>
</div>

在提交表单时将调用的action方法中返回相同的视图。
您可以将结果存储在会话或viewbag等中。。并显示结果。

一种方法是回拨电话

代码如下所示:

@{
    Page.Title = "";
    Layout = "~/_Layout.cshtml";

    if(IsPost)
    {
        string username = Request["username"]; // the request calls the input named "username"

        // here you can type in any C# code you wish
    }
}

<div>
    <form action="" method="post">
        <input type="text" name="username" />
        <input type="submit" value="btn2" />
    </form>
</div>

你的密码在哪里?您要查找的内容已经在VisualStudio中的MVC internet站点模板中。试一试,如果你陷入困境,然后问一个问题。你可能想澄清什么是正确的意思。您可能指的是某种验证,可以通过DataAnnotation实现。确保值不为null、具有最小长度等。