當我嘗試使用get
方法提交表單時,爲什麼ASP.NET Core會在URI中添加一個Plus(+)?Asp.NET Core在URL中添加了一個Plus
例如我有兩個字段來計算BMI:height
和weight
。提交表格後,我得到以下網址:
http://localhost:59953/?height=170&weight+=65
在控制器中,我只得到height
參數,因爲在URL中的權重後,有一個+
。
[HttpGet]
public ActionResult Index(int height, int weight)
{
// The height is 170 but the weight is 0!
return View();
}
這是形式的剃刀代碼:
<form method="get">
<div class="form-group">
<label for="height">Height in cm</label>
<input name="height" id="height" class="form-control"/>
</div>
<div class="form-group">
<label for="weight">Weight in kg</label>
<input name="weight "id="weight" class="form-control"/>
</div>
<button class="btn btn-primary" type="submit">Calculate</button>
</form>
URL中查詢部分的空間被編碼爲加號 – Jamiec