我有麻烦试图让自动完成工作正常.
这一切看起来都不错,但......
<script>
$(function () {
$("#customer-search").autocomplete({
source: 'Customer/GetCustomerByName',
minLength: 3,
select: function (event, ui) {
$("#customer-search").val(ui.item.label);
$("#selected-customer").val(ui.item.label);
}
});
});
</script>
<div>
<input id="customer-search" />
</div>
@Html.Hidden("selected-customer")
Run Code Online (Sandbox Code Playgroud)
但是,当我从下拉列表中选择一个项目时,该值已应用于文本框而不是标签.
我做错了什么?
如果我使用firebug查看源代码,我可以看到我的隐藏字段正在正确更新.
asp.net-mvc jquery jquery-ui autocomplete jquery-ui-autocomplete
我有一个视图,其中包含我的网站条款和条件的单选按钮列表.
例如
Yes
@Html.RadioButtonFor(model => model.TermsAndConditions, "True")
No
@Html.RadioButtonFor(model => model.TermsAndConditions, "False",
new { Checked = "checked" })
</div>
@Html.ValidationStyledMessageFor(model => model.TermsAndConditions)
Run Code Online (Sandbox Code Playgroud)
如果用户完成表单没有任何错误,一切正常,但如果我进行服务器端验证并刷新页面,则会丢失用户为单选按钮做出的选择,并且选定的无线电将返回到默认的假字段.
我是如何绑定radiobutton所以如果用户选择为true,即使在服务器端验证之后,该值仍然保持不变?
任何建议都会很棒!
我是一个全新的mvc,并试图创建一个虚拟应用程序来学习mvc 3.我已经通过音乐商店的例子,现在我试图将它稍微扩展到一个更真实的世界应用程序.有了这个例子你想要任何新项目,你被重定向到创建视图,这是好的,但我想要而不是做一个完整的页面回发我想使用jquery.dialog打开一个模式弹出窗口,将允许用户插入一个新项目.
到目前为止我有
<script type="text/javascript">
$(function () {
$('#dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
title: "hi there",
modal: true,
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$('#my-button').click(function () {
$('#dialog').dialog('open');
});}); </script>
<div id="dialog" title="Create Album" style="overflow: hidden;">
@Html.Partial("_CreateAlbumPartial")</div>
Run Code Online (Sandbox Code Playgroud)
这个问题是每次都不是通过ajax加载局部视图而我真的不知道应该放置局部视图的位置.Shoukld它在共享位置或与其他视图的文件夹中?如何更新控制器类以满足局部视图?
对不起,如果这些很容易,我进入mvc 3天:)
我正在调用web服务,bool字段的返回数据是0或1但是我的模型我使用的是System.Bool
使用Json.Net可以将0/1转换为我的模型的bool吗?
目前我收到一个错误
Newtonsoft.Json.JsonSerializationException:将值"0"转换为类型'System.Boolean'时出错
任何帮助都是极好的!!
我刚刚安装了mvc4 rc更新,我正在尝试构建一个运气不好的api应用程序.
我正在使用ninject但是无法加载我的控制器.我一直在收到错误
类型'Api.Controllers.ConsumerController'没有默认构造函数
我对mvc和使用注射剂都很新,所以请耐心等待.
我没有对通过nuget创建的默认绑定做任何特殊操作
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => …Run Code Online (Sandbox Code Playgroud) 我跟随音乐商店的例子来尝试学习ASP.NET MVC.我正在创建一本食谱应用程序.
我创建了我的viewmodel,如下所示:
namespace CookMe_MVC.ViewModels
{
public class CookMeIndexViewModel
{
public int NumberOfReceipes { get; set; }
public List<string> ReceipeName { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样
public ActionResult Index()
{
var meals= new List<string> { "Dinner 1", "Dinner 2", "3rd not sure" };
//create the view model
var viewModel = new CookMeIndexViewModel
{
NumberOfReceipes = meals.Count(),
ReceipeName = meals
};
return View(viewModel);
}
Run Code Online (Sandbox Code Playgroud)
最后,我的观点看起来像这样
@model IEnumerable<CookMe_MVC.ViewModels.CookMeIndexViewModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr> …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我正在创建的网页上进行jQuery验证.我有大约6个不同的字段集,其中包含页面的详细信息.我正在使用它,因为我隐藏并向他们展示提供更好的用户体验.
每当我尝试提交页面时,无论何时添加单个字符(当文本框需要2个或更多字符时),我都会按照我的要求运行插件,但是我也希望验证发生在onblur上.如果他们没有达到验证条件,我想立即通知我的用户,以便他们可以立即修复它,而不必回来.
任何人都可以告诉我我需要做什么我正在使用*http://bassistance.de/jquery-plugins/jquery-plugin-validation/插件.
这是我到目前为止编写的jQuery代码:
$("#aspnetForm").validate({
rules: {
<%=txtFirstName.UniqueID %>:
{
required: true,
minlength: 2
}
,
<%=txtSurname.UniqueID %>:
{
required: true,
minlength: 2
}
,
<%=txtMobileNumber.UniqueID %>:
{
required: true,
minlength: 8
}
,
<%=Email.UniqueID %>:
{
required: true,
email: true
}
,
<%=ddDay.UniqueID %>:
{
required: true
}
,
<%=ddMonth.UniqueID %>:
{
required: true
}
,
<%=ddYear.UniqueID %>:
{
required: true
}
,
<%=txtHouseNumber.UniqueID %>:
{
required: true,
minlength:1
}
,
<%=txtAddress1.UniqueID %>:
{
required: true,
minlength:5 …Run Code Online (Sandbox Code Playgroud) 这可能很简单,但我似乎无法自己解决.我创建了一个简单的数据库和实体模式,看起来像这样

我正在尝试创建一个允许我添加新订单的创建表单.我总共有3个表,所以我想要的是允许此人输入订单日期的表单,还有一个下拉列表,允许我从产品表中选择一个产品
我希望能够创建一个Add或Edit视图,允许我将OrderDate插入OrderTable,并将OrderID和选定的ProductID插入OrderProduct.
我需要在这做什么步骤.
我创建了一个OrderController并勾选了"添加操作",然后添加了一个看起来像这样的Create View
@model Test.OrderProduct
@{
ViewBag.Title = "Create2";
}
<h2>Create2</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>OrderProduct</legend>
<div class="editor-label">
@Html.LabelFor(model => model.OrderID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.OrderID)
@Html.ValidationMessageFor(model => model.OrderID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProductID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProductID)
@Html.ValidationMessageFor(model => model.ProductID)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Run Code Online (Sandbox Code Playgroud)
这将创建包含OrderID和ProductID文本框的视图,但不包含日期.
我的控制器CreatePost还没有改变
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{ …Run Code Online (Sandbox Code Playgroud) 我创建了一个视图和一个控制器,控制器我想要返回一些搜索结果.我使用jquery调用控制器
<input type="text" id="caption" />
<a href="#" id="search">Search</a>
<script>
$("#search").click(function () {
alert('called');
var p = { Data: $('#search').val() };
$.ajax({
url: '/Ingredients/Search',
type: "POST",
data: JSON.stringify(p),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function () {
alert("error");
}
});
});
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样
[HttpPost]
public ActionResult Search(string input)
{
var result = _db.Ingredients.Where(i => i.IngredientName == input);
return new JsonResult() {Data = new {name="Hello There"}};
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道如何从我的jquery调用中获取varible进入控制器,我在控制器上放置了一个断点并且它被命中但是输入字符串始终为null.
我做错了什么?
我有一个看起来像的视图模型.
public class StoreItemViewModel
{
public Guid ItemId { get; set; }
public List<Guid> StoreIds { get; set; }
[Required]
public string Description { get; set; }
//[Required]
//[DataMember(IsRequired = true)]
public int ItemTypeId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个使用RestSharp的小帮手.
public static IRestResponse Create<T>(object objectToUpdate, string apiEndPoint) where T : new()
{
var client = new RestClient(CreateBaseUrl(null))
{
Authenticator = new HttpBasicAuthenticator("user", "Password1")
};
var request = new RestRequest(apiEndPoint, Method.POST);
//request.JsonSerializer = new JsonSerializer();
// {RequestFormat = DataFormat.Json};
request.AddObject(objectToUpdate);
// …Run Code Online (Sandbox Code Playgroud) c# ×3
jquery ×3
asp.net-mvc ×2
json.net ×2
razor ×2
asp.net ×1
autocomplete ×1
c#-4.0 ×1
html-helper ×1
jquery-ui ×1
onblur ×1
restsharp ×1
wcf-web-api ×1