Form doesn't load on razor page

Viewed 36

I made a simple application in asp.net with a controller and a simple form. But the form doesn't appear when I load the page. Here is the .cshtml code:

<h2>Create</h2>
<form method="post" action="/SUBSCRIPTIONS/CreatePost">  
    <label for="txtName">Your name:</label>  
    <input type="text" id="txtName" name="UserName" />  

    <label for="txtAge">Your age:</label>  
    <input type="number" id="txtAge" name="UserAge" />  

    <button type="submit">Submit</button>  
</form>

And the controller looks like this:

public class SUBSCRIPTIONSController : Controller  
{  
    [HttpGet]  
    public ActionResult Create()  
    {  
        return View();  
    }  

    [HttpPost]  
    public ActionResult CreatePost()  
    {  
        return Content("Hello, " + HttpContext.Request.Form["UserName"] + ". You are " + HttpContext.Request.Form["UserAge"] + " years old!");  
    }  
}

However when I go to localhost:44305/SUBSCRIPTIONS/Create the page doesn't show the form. Only shows the title (Create). What am I doing wrong?

0 Answers
Related