您好我有这个观点索引:
<h1>Přidání nové reklamy do systému</h1>
<div class="row">
<div class="col-md-12">
<div class="row">
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @area = "Home", @role = "form" }))
{
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="typ_reklamy">Typ reklamy</label>
<div class="col-md-8">
<select id="fnivel" name="typ_reklamy" class="form-control">
<option value="1">Reklama na určitou částku</option>
<option value="2">Reklama na určitou dobu</option>
<option style="display:none;" value="3">Reklama na určitý počet kliknutí</option>
</select>
</div>
</div>
}
</div>
</div>
</div>
当我在selecet中选择此选项时:
<option value="1">Reklama na určitou částku</option>
我需要在此页面上:
<h1>Přidání nové reklamy do systému</h1>
<div class="row">
<div class="col-md-12">
<div class="row">
@using (Html.BeginForm("Detail", "Home", FormMethod.Post, new { @area = "Home", @role = "form" }))
{
<fieldset>
<div class="form-group" id="fnivel2" style="margin-bottom:10px;">
<label class="col-md-3 control-label" for="datumz">Datum začátku</label>
<div class="col-md-7">
<div class="editor-field">
<input id="textinput" readonly name="datumz" type="text" value="@Model.allAdvert.datumz" class="form-control input-md" />
</div>
</div>
</div>
<div class="form-group" id="fnivel3" style="margin-bottom:10px;">
<label class="col-md-3 control-label" for="datumk">Datum konce</label>
<div class="col-md-7">
<div class="editor-field">
<input id="textinput" readonly name="datumk" type="text" value="@Model.allAdvert.datumk" class="form-control input-md" />
</div>
</div>
</div>
</fieldset>
}
</div>
</div>
</div>
隐藏这两个输入:
<div class="form-group" id="fnivel2" style="margin-bottom:10px;">
<label class="col-md-3 control-label" for="datumz">Datum začátku</label>
<div class="col-md-7">
<div class="editor-field">
<input id="textinput" readonly name="datumz" type="text" value="@Model.allAdvert.datumz" class="form-control input-md" />
</div>
</div>
</div>
<div class="form-group" id="fnivel3" style="margin-bottom:10px;">
<label class="col-md-3 control-label" for="datumk">Datum konce</label>
<div class="col-md-7">
<div class="editor-field">
<input id="textinput" readonly name="datumk" type="text" value="@Model.allAdvert.datumk" class="form-control input-md" />
</div>
</div>
但我不知道如何在mvc中实现这一目标。
问题是如何将视图索引中的选项值传递给视图细节。
请你能帮帮我吗?
答案 0 :(得分:0)
Use onchange="postvalues()" event and post values and catch in action JavaScript function function postvalues() { $.ajax({ url: '/home/Detail', type: 'POST', data: { optionvalue: $("#fnivel").val() }, dataType: 'json', success: success }); } In controller [HttpPost] public ActionResult Detail(string optionvalue) { ViewBag.Optionvalue=optionvalue return View(); }