私はユーザー名とパスワードとコードを持つログインモデルを持っています。自動的にモデルデータを記入する方法
次に、コードを入力すると自動的に関連付けられたユーザー名とパスワードが入力されていなければなりません。たとえば、コードをHDで入力した後、ユーザー名とパスワードのテキストフィールドに充填されて
アクションメソッドは次のようになります。
[HttpPost]
public ActionResult LoginBalieUser(V_LoginModel_BalieUser model)
{
ISalesPersonProfile salesAgent99 = CommerceFrameworkBase.SalesPersons.GetSalesPerson("HD");
var salesAgent = CommerceFramework.ShopAccounts.GetShopAccount(Guid.Parse("3E90BB13-36BA-435D-8ED7-E930A4F8C758"), true);
if (model.BalieCode == salesAgent99.Id)
{
if (!ModelState.IsValid)
return View(model);
if (!ShopApi.UserState.Login(model.UserName, model.Password, model.RememberMe))
{
ModelState.AddModelError("","The username or password is incorrect");
return View(model);
}
}
return RedirectToAction("Index", "Profile");
}
拡張モデルは次のようになります。
public class V_LoginModel_BalieUser : LoginModel
{
public string BalieCode { get; set; }
}
とかiginalモデルは次のようになります。
//
// Summary:
// A model to login into the webshop.
public class LoginModel
{
public LoginModel();
//
// Summary:
// Gets or sets the password.
[AllowHtml]
[DataType(DataType.Password)]
[Display(Name = "Password")]
[Required(ErrorMessageResourceName = "Validation_RequiredField")]
[StringLength(30, ErrorMessageResourceName = "Validation_MaxLengthExceeded")]
public virtual System.String Password { get; set; }
//
// Summary:
// Gets or sets a value indicating whether to remember the user to login him automatically
// on the next visit.
[Display(Name = "Login_RememberMe")]
public virtual System.Boolean RememberMe { get; set; }
//
// Summary:
// Gets or sets the username.
[DataType(DataType.EmailAddress, ErrorMessageResourceName = "Validation_InvalidField")]
[Display(Name = "EmailAddress")]
[Required(ErrorMessageResourceName = "Validation_RequiredField")]
[StringLength(80, ErrorMessageResourceName = "Validation_MaxLengthExceeded")]
[TrimAttribute(new[] { })]
public virtual System.String UserName { get; set; }
}
とビューは次のようになります。
@{
Layout = LayoutPaths.General;
}
@model Sana.Commerce.DomainModel.Account.V_LoginModel_BalieUser
<div class="semicolumn">
<div class="form-holder">
@using (Html.BeginForm(htmlAttributes: new { @class = "form" }))
{
@Html.AntiForgeryToken()
<table>
<tr>
<th>
@Html.DisplayNameFor(modelItem => modelItem.BalieCode)
</th>
<th></th>
</tr>
<tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.BalieCode)
</td>
</tr>
<tr>
<th>
@Html.DisplayNameFor(modelItem => modelItem.UserName)
</th>
<th></th>
</tr>
<tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.UserName)
</td>
</tr>
<tr>
<th>
@Html.DisplayNameFor(modelItem => modelItem.Password)
</th>
<th></th>
</tr>
<tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.Password)
</td>
</tr>
</table>
<div class="form-row">
<h4></h4>
<input type="submit" value="Login" />
</div>
}
</div>
<div>
</div>
</div>
@section Scripts{
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$("#Id").change(function() {
$.ajax({
type: "Get",
url: '@Url.Action("loginbalieUser", "profile")',
data: { id: $("").val() },
dataType: "json",
success: function (data) {
$("#UserName").val(data[0]);
$("#Password").val(data[1]);
}
});
})
});
</script>
}
だから私はAjax呼び出しを試してみました。しかし、正確な実装私は知らない。 ISalesPersonProfile
//
// Summary:
// Interface for the Sales Person Profile entity.
public interface ISalesPersonProfile : IEntity
{
//
// Summary:
// Email of this Sales person.
string Email { get; set; }
//
// Summary:
// Sales person's code.
string Id { get; set; }
//
// Summary:
// Job Title of the Sales person.
string JobTitle { get; set; }
//
// Summary:
// Name of the Sales person.
string Name { get; set; }
//
// Summary:
// Phone number of the Sales person.
string Phone { get; set; }
//
// Summary:
// Gets or sets the related customer id list related with the sales person.
IList<string> RelatedCustomerIds { get; set; }
}
しかし、私はこのエラーを取得:
loginbalieUser:232 Uncaught ReferenceError: ValidateBalieCode is not defined
at HTMLInputElement.onchange (loginbalieUser:232) on this line: <tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.BalieCode, new { @onchange = "ValidateBalieCode()" })
</td>
</tr>
をして、これは私のAJAX呼び出しです:
function ValidateBalieCode(){
var code = $('input#BalieCode').val();
$.ajax({
type: "Get",
url: '@Url.Action("ValidateBalieCode", "profile")',
data: { "BalieCode":code },
success: function (data) {
$("input#UserName").val(data.UserName);
$("input#Password").val(data.Password);
}
});
}
が、これはモデルであるあなたに
ありがとうございました
D GOOGクロームでのページ:私はこのように今それを持っている
function ValidateBalieCode(){
var code = $('input#BalieCode').val();
$.ajax({
type: "Get",
url: '/sitemap.xml',
data: { "BalieCode":code },
success: function (data) {
$("input#UserName").val(data.UserName);
$("input#Password").val(data.Password);
}
});
}
おけば、
:
function ValidateBalieCode() {
var code = $('input#BalieCode').val();
$.ajax({
async: true,
type: "Get",
url: "/profile/ValidateBalieCode/",
contentType: "application/json; charset=utf-8",
data: { "BalieCode": code },
success: function (data) {
$("input#UserName").val(data.UserName);
$("input#Password").val(data.Password);
}
});
}
が、URLは次のようなものです:
は、私がこれを見ます
http://localhost:5923/en-us/profile/loginbalieuser
いつも:en-米国。
url: "en-us/profile/ValidateBalieCode/",
はその後、クロームで、私はこれを参照してください:私はこれを行う場合は
http://localhost:5923/en-us/profile/en-us/profile/ValidateBalieCode/?BalieCode=1 404 (Not Found)
私はID '#Id'を持つ任意のコントロールを見つけることができませんでした。それで '$("#Id ")とは何ですか?変更' – mmushtaq
あなたの返事をありがとう。私はidがsalesAgent99のIDだと思った投稿を編集します。私はAjaxでそれを行う方法を正確にはわかりません –
あなたの質問を理解することは本当に難しいです。あなたの 'LoginBalieUser'アクションは' HttpPost'でマークされ、あなたのajaxでは 'get'を指定します。 – mmushtaq