我有一个CodesController,Index 操作看起来像这样。
public ActionResult Index(int id, string manufacturerName)
我希望 URL 看起来像http://www.domain.com/codes/[id]/[manufacturerName]但我目前使用的代码看起来像http://www.domain.com/代码/[id]?manufacturerName=[manufacturerName]
<script type="text/javascript">
$(function() {
$('#btnNext').click(function () {
var _id = $('#ddlManufacturers').val();
var _manufacturerName = $('#ddlManufacturers').text();
var url = '@Url.Action("Index", "Codes", new { id = "_id", manufacturerName = "_manufacturerName" })'
.replace('_id', _id).replace('_manufacturerName', _manufacturerName.toLowerCase().trim());
window.location.href = url;
});
});
这就是我现在的做法,不知道如何正确地做到这一点,所以 URL 变成了我想要的方式。编码