Home > Net >  A very simple MVC submission form page, how to match? Ask for help.
A very simple MVC submission form page, how to match? Ask for help.

Time:04-16

With an example of web page learning a process form the MVC example, how to match? Submit the form doesn't work, is the page refresh, ask for help!

OkController page located in the Controller folder, the following code================

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. Mvc;

The namespace WebApplication1. Models
{
Public class okController: Controller
{
//
//GET/ok/:
Public ActionResult Index ()
{
Return the View ();
}
}
Public class person
{
//[Required] (ErrorMessage="please enter the name")
Public string name {get; set; }
Public string email {get; set; }

}

}

LoginController page is also under the Controller folder, the following code================

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. Mvc;

The namespace WebApplication1. Controllers
{
Public class LoginController: Controller
{
//
//GET/Login/:
Public ActionResult Index ()
{

Response. Write (" not right!" );
Return the View ();
}
Public ActionResult Login ()
{

Response. Write (" not right!" );
Return the View ();
}
}
}

Complete index.cshtml in Views/Home, the code is as follows:==================

@ model WebApplication1. Models. The person
@ {
Layout=null;
}





This is a web page & lt;/title> <br/></head> <br/><body> <br/><br/><br/>@ the using (Html BeginForm ()) <br/>{<br/><br/><P> Your name: @ Html. TextBoxFor (model=& gt; Model. The name) & lt;/p> <br/><P> Email address: @ Html. TextBoxFor (model=& gt; Model. Email) & lt;/p> <br/><br/><Input type="submit" value="submit button" https://bbs.csdn.net/topics//& gt; <br/>} <br/><br/><br/></body> <br/><br/></html> <br/><br/>======================finish code============<br/>Submission is finished a page refresh, I study on rough, a little, please advise how to deal with, even if hit a "is not correct!" ? <br/><br/><br/><p class="article - content rp"> CodePudding user response: </p>Html. BeginForm (" ActionName ", "ControllerName", FormMethod method)<p class="article - content rp"> CodePudding user response: </p>Is there an action parameter forgot to fill in, so you can know where the form is submitted, you used this thing for a long time,<p class="article - content rp"> CodePudding user response: </p>Submitted to which method, receiving can have effect, but also need to jump in the background to write ah<p class="article - content rp"> CodePudding user response: </p><fieldset> <legend> refer to hand on the keyboard to knock on the second floor is very light response: <legend> <blockquote> is there an action parameter forgot to fill in, so you can know where the form is submitted, you used it a long time, the </blockquote> <fieldset> <br/>I see example is written, so he can run up and handle is equivalent to the default for this page?<p class="article - content rp"> CodePudding user response: </p><fieldset> <legend> Hello World, 1/f, reference response: <legend> <blockquote> Html. BeginForm (" ActionName ", "ControllerName", FormMethod method) </blockquote> <fieldset> <br/>I changed to such a using (Html. BeginForm (" Login ", "LoginController, FormMethod. Post)) tip can't find the page, where is wrong? </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/net/108142.html" target="_blank" style="color:#999">https//www.codepudding.com/net/108142.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/net/108141.html'>WPF window is turned off, why not release the memory</a></div> <div class="detail-arr-right">Next:<a href='/net/108143.html'>Reflection is not referenced DLL, can create instances of the class to interface</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=ASP.NET' target='_blank'>ASP.NET</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>