如何在同一个视图中将项目从一个列表框移动到另一个列表框,而不必重新加载整个页面,只需更新ASP MVC 4中的两个列表框?
这是为了拥有一些选定的音乐流派,然后能够通过提交按钮将这些音乐流派提交到网络服务.
类型具有不应显示的id和应显示的名称.
我试图在过去的4个小时内搞清楚,但我似乎无法完成任何工作.
我解决了使用jQuery移动项目的问题.我添加了对jquery.unobtrusive-ajax.js的引用,并为视图添加了一些方法.最终视图如下所示:
SelectGenre.cshtml
@model SelectGenreModel
<div id="genreDiv">
@Html.ListBoxFor(model => model.AvailableGenres, new MultiSelectList(Model.AvailableGenres, "Id", "Name"), new { size = "10" })
<input id="btnAddAll" type="button" value=" >> " onclick="addallItems();" />
<input id="btnAdd" type="button" value=" > " onclick="addItem();" />
<input id="btnRemove" type="button" value=" < " onclick="removeItem();" />
<input id="btnRemoveAll"type="button" value=" << " onclick="removeallItems();" />
@Html.ListBoxFor(model => model.ChosenGenres, new MultiSelectList(Model.ChosenGenres, "Id", "Name"), new { size = "10" })
</div>
<script type="text/javascript">
function addItem() {
$("#AvailableGenres option:selected").appendTo("#ChosenGenres"); …Run Code Online (Sandbox Code Playgroud) 我有一个页面,您可以在其中创建频道.频道有与之相关的流派.
CreateChannel.cshtml
<h2>Create Channel</h2>
<div class="row-fluid">
<div>
@{
using (Html.BeginForm("CreateNewChannel", "Channel", new { channelId = Model.Id, userId = @Session["userId"] }, FormMethod.Post))
{
@Html.HiddenFor(model => model.Id)
<h5>Name</h5>
@Html.TextBoxFor(model => model.Name, new { @class = "input-block-level pull-left", type = "text", required = "required", placeholder = "Channel Name", style = "width: 400px" })
@Html.ValidationMessageFor(model => model.Name, null, new { @class = "txt-error error-field", style = "padding-top: 4px" })
<div class="clearfix"></div>
<div style="width: 400px" class="input-block-level">
<h5 style="">Description</h5>
<div class="input-block-level">
@Html.TextAreaFor(model => model.Description, 5, 60, …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用F#和函数式编程.我想知道如何在一个元组中创建一个函数,我定义第一个值必须是一个字符串,而不是标准的int.
例:
复制字符串的函数s,n次数并返回它.我现在拥有的是:
let rec pow2 = function
| (s:string,0) -> ""
| (s:string,n) -> s + pow2(s,n-1)
Run Code Online (Sandbox Code Playgroud)
这有效,但我认为有一种比定义s:string每个案例更好的方法.
(我知道String.replicate,这不是为了效果,而是学习)