在asp.net核心之前,我会通过从按钮点击后面写一些jquery来从按钮调用web api。
然后我将处理该api调用返回的数据。
目前我有一个观点。此视图包含一个弹出窗口。在那个窗口中,我有3个div部分。
登录 注册 ForgottenPassword
专注于注册div我允许用户输入电子邮件/密码/确认密码,让他们按下调用我的web api的按钮来验证此过程。
所以,这是我的父视图片段:
@model InformedWorker.Services.Models.Account
<div id="divLogForm" class="modal-dialog" style="display:none;position:absolute; ">
<div style="background-color: #fefefe;margin: auto;padding: 20px;border: 1px solid #888;">
<div class="modal-header">
<button id="btnClose" type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="hdrTitle">LogIn</h4>
</div>
<div class="modal-body">
@{Html.RenderPartial("~/Views/Segments/_Registration.cshtml", Model.Registration);}
@{Html.RenderPartial("~/Views/Segments/_LogIn.cshtml", Model.LogIn);}
@{Html.RenderPartial("~/Views/Segments/_ForgottenRegistration.cshtml", Model.ForgottenloginDetails);}
</div>
</div>
</div>
我的注册局部视图是:
@model InformedWorker.Services.Models.Registration
@*
*@
<div class="row" style="display:none" id="divRegistration">
<div class="col-xs-6">
<div class="well">
<div class="form-group">
<label asp-for="EmailAddress" class="control-label"></label>
<input type="text" class="form-control" id="EmailAddress" name="EmailAddress" value="@Model.EmailAddress" required="" title="Please enter you username" placeholder="example@gmail.com">
<span class="help-block"></span>
</div>
<div class="form-group">
<label asp-for="Password" class="control-label">Password</label>
<input type="password" class="form-control" id="Password" name="Password" value="" required="" title="Please enter your password">
<span class="help-block"></span>
</div>
<div class="form-group">
<label asp-for="ConfirmPassword" class="control-label"></label>
<input type="password" class="form-control" id="ConfirmPassword" name="ConfirmPassword" value="" required="" title="Please confirm your password">
</div>
<div id="registerErrorMsg" class="alert alert-error hide">Invalid registration</div>
<a asp-area="" asp-controller="api/Registration" asp-action="Register" class="btn btn-success btn-block">Register</a>
</div>
</div>
<div class="col-xs-6">
<p class="lead">Already Registered?</p>
<p><a onclick="showLogInPage();" class="btn btn-info btn-block">LogIn</a></p>
</div>
</div>
我的帐户模型是这样的:
public class Account
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long AccountId { get; set; }
public string AccountRef { get; set; }
[Display(Name = "Company Name")]
public string CompanyName { get; set; }
[Display(Name = "Email Address")]
[Required]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address not found")]
[StringLength(60, MinimumLength = 3)]
public string EmailAddress { get; set; }
public string Salt { get; set; }
public string Hash { get; set; }
public bool Disabled { get; set; }
[Display(Name = "Date of Entry")]
public DateTime DOE { get; set; }
public ICollection<Client> Clients { get; set; }
public bool Activated { get; set; }
[NotMapped]
public Registration Registration { get; set; }
[NotMapped]
public LogIn LogIn { get; set; }
[NotMapped]
public ForgottenRegistration ForgottenRegistration { get; set; }
}
我的homeController是这样的:
public IActionResult Index()
{
//var home = new Services.Models.Home();
//home.MyTest = _localizer["ActivationEmailSent"];
//return View(home);
var test = new Services.Models.Account();
test.Registration = new Services.Models.Registration();
test.Registration.EmailAddress = "aaa";
return View(test);
//return View(new Services.Models.Account());
}
我的注册网站api就是这样:
[Route("api/[controller]")]
public class Registration : Controller
{
// GET api/values/5
[HttpGet("{id}")]
public string Get(Registration Account)//int id)
{
return "Error in reg";
}
}
所以我的问题是,当调用api时,整个页面被'value'替换。
如何解析数据并使用结果填充表单字段并保留原始视图?
我应该恢复到jquery并以这种方式打电话给api吗?
我从根本上错了吗?
由于