2017-04-01 1 views
1

私のASP.NET MVCアプリケーションに問題があります。以前に作成した既存のオブジェクトを別のActionResultに変更するにはどうすればよいですか? 「ASP.NETの既存のオブジェクトを変更する

public ActionResult getLogin(AccountViewModel accountViewModel) 
{ 
    Account account2 = de.Accounts.FirstOrDefault(a => a.Username == accountViewModel.Account.Username); 
    PasswordReminder.PasswordReminder reminder = new PasswordReminder.PasswordReminder(); 
    reminder.showQuestion(account2.Username); 
    return View("Question", reminder); 
} 

そして私は、属性にこののActionResult私の見る「回答」でそう

@model PasswordReminder.PasswordReminder 
@{ 
Layout = null; 
<html> 
<head> 
<meta name="viewport" content="width=device-width" /> 
<title>Question</title> 
</head> 
<body> 
<div> 
@Model.questionReminder 
    @using (Html.BeginForm("Answer", "Account", FormMethod.Post)) 
    { 
     @Html.TextBoxFor(a => a.reminderAnswer) 
     <input type="submit" value="Send" /> 
    } 
</div> 
</body> 
</html> 

することにより、既存のリマインダーオブジェクトに属性を追加する:

私はこのアクションでオブジェクトを作成しましたreminderAnswer "私は値を入力しましたが、questionReminderはnullなので、これは新しいオブジェクトでなければなりません..すべてのおかげで、

答えて

0

私はあなたの質問を正しく理解していれば、モデルを使用しているPasswordReminderオブジェクトは、getLoginアクションで永続化されてから、モデルとして別々に返されて、Answerビューにフィードされます(ただし、ViewModelを次のように使用することをお勧めします)。

これは、reminderAnswerプロパティの値を変更するために、以前にインスタンス化されたPasswordReminderオブジェクトをアンサービューで参照していることを保証します。

関連する問題