0
私は、顧客がログインして発生した質問を提出し、名前を入力して問題を説明できるMVCアプリケーションを用意しています。私たちのサポート電子メールアドレスは私たちのサーバー電子メールを介して、そうすることで、私は電子メールに文字列としてユーザーのログインした電子メールアドレスを含める必要があります。私はいくつかの方法を試しましたが、電子メールフィールドがnullを返すときに実行時エラーが発生します。ログインしたユーザーの電子メールアドレスを取得して電子メールで受け取ります
マイコントローラ:私は答えとして書いたものを入れていた場合、これは、電子メール
Email.Body = $"<p><b>Name:</b> {support.UserNameSurname}</p> <p><b>Email:</b> {support.Email=User.Identity.GetUserName()}</p> <p><b>Message:</b> {support.SupportMessage}</p>";
ビュー
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="col-sm-offset-3 col-sm-6">
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.UserNameSurname, "Full Name" , htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.EditorFor(model => model.UserNameSurname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserNameSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SupportMessage,"Describe Issue", htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.TextAreaFor(model => model.SupportMessage, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SupportMessage, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Request Help" class="btn btn-default" style="background-color: #0a9dbd;-webkit-text-fill-color: white; border-color: #0a9dbd; height: 40px; float:right;" />
</div>
<div>
@Html.ActionLink("Back to List", "CustomerView")
</div>
</div>
</div>
</div>
}
それは 'User.Identity.GetUserName()'はヌル値を返しますか? –
User.Identity.Nameを使用してみましたか? – Shahbaz
はい、nullを返しています –