如何在F#MVC5 Web应用程序中使用Razor传递数据。
例如,在下面的视图中, PostEmail 表单发布时,如何传递 newEmail 输入的值以及中的某些字段ViewData的
对于 DeleteEmail 表单,如何从电子邮件中选择所选的选项值?
我的观点:(Settings.cshtml)
<div style="width: 100%;">
<h2 id="title" style="margin: 0 auto;">@ViewBag.PageTitle</h2> <br> <br>
<div style="width: 60%; margin: 0 auto;">
<div style="float: left; clear: none; width: 45%;">
<span>EMAILS</span> <br>
@using (Html.BeginForm("DeleteEmail", "QualityScore", FormMethod.Post))
{
<select id="emails" size="10" style="width: 100%; max-width: 100%">
@foreach (string email in ViewBag.EmailList)
{
<option value="@email">@email</option>
}
</select>
<input type="submit" id=" email_delete" value="Delete" />
}
@using (Html.BeginForm("PostEmail", "QualityScore", FormMethod.Post))
{
<input id="newEmail" />
<input type="submit" id="email_create" value="Create" />
}
</div>
</div>
</div>
我的控制器:(QualityScoreController.fs)
type QualityScoreController(queries : DataQueries) =
inherit Controller()
new () = new QualityScoreController(DataQueries())
member this.Settings(token) =
let db = DataConnection.GetDataContext()
let user = queries.FindUserByToken(token, db)
this.ViewData.Add("PageTitle", "Your QualityScore Report Settings")
this.ViewData.Add("EmailList", queries.FindUsersReportEmails(user.Id, db))
this.ViewData.Add("KeywordList", queries.FindUsersReportBrands(user.Id, db))
this.ViewData.Add("UserID", user.Id)
this.View()
member this.PostEmail() =
... //need to use information sent from the form
member this.DeleteEmail() =
... //need to use information sent from the form
我的解决方案
我的观点:(Settings.cshtml)
<div style="width: 100%;">
<h2 id="title" style="margin: 0 auto;">@ViewBag.PageTitle</h2> <br> <br>
<div style="width: 60%; margin: 0 auto;">
<div style="float: left; clear: none; width: 45%;">
<span>EMAILS</span> <br>
@using (Html.BeginForm("DeleteEmail", "QualityScore", FormMethod.Post))
{
<select name="emails" size="10" style="width: 100%; max-width: 100%">
@foreach (string email in ViewBag.EmailList)
{
<option value="@email">@email</option>
}
</select>
<input type="submit" id=" email_delete" value="Delete" />
<input name="userid" none value="@ViewBag.UserID" />
}
@using (Html.BeginForm("PostEmail", "QualityScore", FormMethod.Post))
{
<input name="newEmail" />
<input type="submit" id="email_create" value="Create" />
<input name="userid" none value="@ViewBag.UserID" />
}
</div>
</div>
</div>
我的控制器:(QualityScoreController.fs)
type QualityScoreController(queries : DataQueries) =
inherit Controller()
new () = new QualityScoreController(DataQueries())
member this.Settings(token) =
let db = DataConnection.GetDataContext()
let user = queries.FindUserByToken(token, db)
this.ViewData.Add("PageTitle", "Your QualityScore Report Settings")
this.ViewData.Add("EmailList", queries.FindUsersReportEmails(user.Id, db))
this.ViewData.Add("KeywordList", queries.FindUsersReportBrands(user.Id, db))
this.ViewData.Add("UserID", user.Id)
this.View()
member this.PostEmail(newEmail: string, userid : int) =
...
member this.DeleteEmail(emails : string, userid : int) =
...
答案 0 :(得分:1)
ASP.NET MVC会自动将表单值绑定到您的操作的同名参数:
auto ptr = do_something();
auto output = static_cast<another*>(ptr.get());