我覺得自己像個白癡,但對於我的生活卻無法弄清楚我在這裏失去了什麼。關於局部視圖的另一個問題
我有以下幾點:
@section TopPane
{ @ * @ {Html.Action( 「_ OpenIDSignInPartial」, 「賬戶」);} * @
@ {Html.RenderAction(「_ OpenIDSignInPartial 」, 「賬戶」);}
登錄與您mysite.com帳戶或註冊一個帳號 @ {Html.RenderPartial( 「_ LoginPartial」);} @ {Html.RenderPartial( 「_ RegisterPartial」);}}
正如你可以看到我已經被渲染3個部分景色。 現在的控制器代碼----
public class AccountController : Controller
{
private readonly IAuthenticationService _authenticationService;
OpenIdRelyingParty _openIdRelyingParty = new OpenIdRelyingParty(null);
public AccountController(IAuthenticationService authenticationService)
{
_authenticationService = authenticationService;
}
public ActionResult Index()
{
return View();
}
public ActionResult SignIn()
{
return View();
}
[HttpPost]
public ActionResult SignIn(AccountSignInViewModel accountSignInViewModel)
{
return View();
}
public ActionResult OpenIdSignIn()
{
AccountIndexViewModel accountIndexViewModel = new AccountIndexViewModel();
IAuthenticationResponse authenticationResponse = _openIdRelyingParty.GetResponse();
switch (authenticationResponse.Status)
{
case AuthenticationStatus.Authenticated:
try
{
var claimedIdentifier = authenticationResponse.ClaimedIdentifier.ToString();
_authenticationService.OpenIdSignIn(claimedIdentifier);
}
catch (Exception)
{
// Do something with this man!
throw;
}
break;
case AuthenticationStatus.Canceled:
accountIndexViewModel.openIdSignInViewModel.ErrorMessage = "An Error Message";
break;
}
return View("SignIn",accountIndexViewModel); // ALWAYS an ERROR
}
[HttpPost]
public ActionResult OpenIdSignIn(AccountOpenIdSignInViewModel accountOpenIdSignInViewModel)
{
IAuthenticationResponse authenticationResponse = _openIdRelyingParty.GetResponse();
if (authenticationResponse == null)
{
Identifier identifier;
if (Identifier.TryParse(accountOpenIdSignInViewModel.openid_identifier, out identifier))
{
try
{
IAuthenticationRequest request =
_openIdRelyingParty.CreateRequest(accountOpenIdSignInViewModel.openid_identifier);
return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException protocolException) // Prolly should add some errors to the model
{
ModelState.AddModelError("openid_identifier","Unable to authenticate");
return View("SignIn");
}
}
}
return View();
}
public ActionResult _OpenIDSignInPartial(AccountOpenIdSignInViewModel accountOpenIdSignInViewModel)
{
return PartialView("_OpenIdSignInPartial");
}
}
當我reurn從OpenIdSignIn的ActionResult()認爲我收到以下錯誤 傳遞到字典的模型項的類型爲「Web.ViewModels.AccountIndexViewModel ',但是這個字典需要一個'Web.ViewModels.AccountSignInViewModel'類型的模型項。 好吧,所以我會返回一個的InputInModel對嗎?然後我得到一個錯誤,說它需要AccountIndexViewModel ... CATCH 22這裏。
甜,讓我試試看,然後馬上回來。一如既往感謝Darin。 – CrazyCoderz 2011-05-28 13:34:28
作品偉大的先生。你太棒了。 – CrazyCoderz 2011-05-28 13:37:28