【发布时间】:2021-07-28 02:35:58
【问题描述】:
我对 ASP.net 编程相当陌生,但我仍然熟悉 C# 和 C 语言。我最初被教导如何浏览 ASP.net Razor 页面。这是简单易行的。但是对于我的最后一个项目,我继续做了一个 ASP.net 核心 MVC 页面。到目前为止,它很好并且可以工作(工作原理相似),除了后端部分。在 razor 页面中,页面是在一起的,index.cshtml 和 index.cshtml.cs 在一个地方,但在 MVC 中并非如此。我很难理解如何在我的页面中使用method="post"。
我的剃须刀查看页面代码:
@{
ViewData["Title"] = "Lorem Ipsum Generator";
Layout = "/Views/Shared/_Layout.cshtml";
}
<style>
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
font-family: Kalam, cursive;
}
nav {
height: 100%;
width: 100%;
left: 0;
right: 0;
top: 0;
bottom: 0;
position: absolute;
background: linear-gradient(135deg, #a8e6cf, #dcedc1, #ffd3b6, #ffaaa5, #ff8b94);
background-size: 200% 200%;
animation: rainbow 10s alternate infinite;
}
.JK {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #04AA6D;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.JK:hover {
background-color: #3e8e41
}
.JK:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
<html>
<body class="text-center">
<form method="post">
<h1 style="font-size:26px;">Lorem Ipsum Generator</h1>
<p>At this page, You will get to generate Lorem Ipsum text, at your desired size and format. Enjoy!</p>
<p>Enter Number of words to generate: <input id="wordx" type="text" value="10" /></p>
<p>Enter Number of paragraphs to generate: <input id="parax" type="text" value="2" /></p>
<p>Include Data and time at the end of the list? (Proxy is allowed!) <input type="radio" id="Y" name="Dt" />Yes <input type="radio" id="N" name="Dt" checked="checked" />No</p>
<p>If you have selected the option "Yes", Please choose a specific time and date: <input type="datetime-local" id="datetimex" /></p>
<p>Do you want the generator to start with "Lorem ipsum dolor sit amet" (Check the box, only if you want): <input type="checkbox" id="startx" />Yes</p>
<p><input type="submit" class="JK" value="Generate!" /></p>
</form>
</body>
</html>
我查看了这个页面:How to call POST method in .NET CORE MVC directly from Razor View? 寻求解决方案,但它并没有像想象的那样锻炼。我正在使用这个 Lorem Lpsum 生成器:https://github.com/EdCharbeneau/Prototyping
任何帮助将不胜感激:)
【问题讨论】:
-
比较简单,在页面模型上写一个
OnPost方法如docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/…即可。
标签: c# post razor asp.net-core-mvc