2017-10-29 70 views
0

我有剃刀形式像這樣在剃刀網址PARAM添加到一個div

@using (Html.BeginForm("ResetPassword", "Login", FormMethod.Post, new { enctype = "multipart/form-data" })) 
      { 
    @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 

    <div id="email_label" style="font-size:14px;padding:8px;">Email:</div> 
    <div class="form-group"> 
     @Html.EditorFor(x => x.user, new { htmlAttributes = new { @class = "form-control", placeholder = "enter email from url" } })<br /> 
     @Html.ValidationMessageFor(x => x.user) 
     </div> 
} 

我想從URL值來代替placeholder = "enter email from url"

網址:example.com/[email protected]&pass=123

現在我正在做這在Javascript,但我想這樣做的剃刀。但我似乎無法得到任何地方。

下面是我在做什麼在Javascript:

let url = new URL(window.location.href); 
let searchParams = new URLSearchParams(url.search); 
let emailAddress = (searchParams.get('email')); 

回答

0

您可以從Request讀取查詢字符串,並使用它

@Html.EditorFor(x => x.user, 
        new { htmlAttributes = new { @class = "form-control", 
           placeholder = Request["email"] ?? "Please enter email" } }) 

,如果它存在,這將讀取電子郵件查詢字符串值「請輸入電子郵件」字符串

這將只添加佔位符文本,而不是輸入的實際值。如果您希望將其設置爲輸入元素值,則可以在GET操作方法中執行此操作。

public ActionResult ResetPassword(string email) 
{ 
    var vm = new ResetPasswordVm { User = email }; 
    return View(vm); 
} 

和渲染輸入

當輔助方法將使用該值