我想在Facebook生日应用中将输入文本从视图传递到控制器: 应用链接:http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-facebook-birthday-app
HomeController中的
[FacebookAuthorize("email", "user_photos")]
public async Task<ActionResult> Index(FacebookContext context)
{
if (ModelState.IsValid)
{
var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
return View(user);
}
return View("Error");
}
[HttpPost]
[FacebookAuthorize("email", "user_photos")]
public async Task<ActionResult> Index(string txt,FacebookContext context)
{
if (ModelState.IsValid)
{
var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
// my code , I use txt here
return View(user);
}
return View("Error");
}
视图:
@using facebookpostc.Models
@using Microsoft.AspNet.Mvc.Facebook.Models
@using Microsoft.AspNet.Mvc.Facebook
@model MyAppUser
@{
ViewBag.Title = "Home Page";
}
<article id="content">
<div class="right">
@using (Html.BeginForm("Index", "HomeController"))
{
<br />
<span>please input your text: </span>
<input type="text" id="txt" name="txt" />
<input type="submit" />
}
</div>
</article>
但它没有传递文本,我试图以多种方式传递文本,但没有传递文本。
答案 0 :(得分:0)
您可以从 FormCollection :
中阅读[HttpPost]
[FacebookAuthorize("email", "user_photos")]
public async Task<ActionResult> Index(FormCollection form,FacebookContext context)
{
if (ModelState.IsValid)
{
string temp = form["txt"].ToString();
var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
// my code , I use txt here
return View(user);
}
return View("Error");
}