我在一个视图中使用了以下内容,以便导航到索引视图上的特定选项卡...
button type="button" class="btn blue" onclick="location.href='Index/#rooms'"><i class="m-icon-swapleft m-icon-white"></i> Back to Room List</button>
网址读起来像.....ReferralTarget/Index/#rooms
房间是索引视图上的选项卡之一。
当我在另一个视图中使用相同的代码时,我收到错误 400 - Bad request 并且 URL 看起来像... /ReferralTarget/EditRoom/Index/#rooms
@model.Project.Web.Models.ReferralTargetRoomModel
@{
ViewBag.Title = "EditRoom";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!-- BEGIN PAGE CONTENT-->
<div class="row-fluid">
<div class="span12">
<!-- BEGIN SAMPLE FORM PORTLET-->
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption"><i class="icon-hospital"></i>Edit Room Details</div>
</div>
<div class="portlet-body form">
<!-- BEGIN FORM-->
@using (Html.BeginForm("EditRoom", "ReferralTarget", FormMethod.Post, new { @class="form-horizontal" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.ReferralTargetId)
<div class="control-group">
<label class="control-label">@Html.LabelFor(model => model.County)</label>
<div class="controls">
@Html.DropDownListFor(model => model.County.ID, new SelectList(Model.Counties, "ID", "Name"), new {@id="counties" })
@Html.ValidationMessageFor(model => model.County)
</div>
<div class="control-group">
<label class="control-label">@Html.LabelFor(model => model.Fax)</label>
<div class="controls">
@Html.EditorFor(model => model.Fax)
@Html.ValidationMessageFor(model => model.Fax)
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.LabelFor(model => model.Email)</label>
<div class="controls">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.LabelFor(model => model.Website)</label>
<div class="controls">
@Html.EditorFor(model => model.Website)
@Html.ValidationMessageFor(model => model.Website)
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.Users)</label>
<div class="controls">
@Html.ListBoxFor(m => m.SelectedUsers, new MultiSelectList(Model.Users,"ID","Name",Model.SelectedUsers)
, new { @id = "users" , @multiple = true})
</div>
</div>
<div class="form-actions">
<input type="submit" value="Save Changes" class="btn green">
<button type="button" class="btn blue" onclick="location.href='Index/#rooms'"><i class="m-icon-swapleft m-icon-white"></i> Back to Room List</button>
</div>
}
<!-- END FORM-->
</div>
</div>
<!-- END SAMPLE FORM PORTLET-->
</div>
<!-- END PAGE CONTENT-->
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/Scripts/jquery.multi-select.js")
}
@section Styles {
<link href="~/assets/css/multi-select.css" rel="stylesheet" />
}
<script type="text/javascript">
$(document).ready(function () {
$(document).ready(function () {
$('#users').multiSelect({
selectableHeader: "<div class='custom-header'>Availible Users</div>",
selectionHeader: "<div class='custom-header'>Selected Users</div>",
});
});
$(function () {
$("#counties").change(function () {
var filterVal = $("#counties").val();
getHospitalsByCounty(filterVal);
})
});
function getHospitalsByCounty(value) {
$.ajax({
url: 'GetHospitalsInCounty?id=' + value,
contentType: "application/json; charset=utf-8",
success: function (response) {
var data = response;
var items = []
$('#hospitals').empty();
$.each(data, function (index, value) {
$('#hospitals').append($('<option></option>').val(value.ID).html(value.Name));
});
}
});
};
});
</script>
有没有办法改变 url 来删除文本,在这种情况下是“编辑房间”..??
如果它与控制器相关,则两个视图的唯一区别是 EditView Get ActionResult 使用(字符串 id),而 AddView 没有....
谢谢