在Web.config文件中使用全球化culture ="da-DK"时,jQuery验证不起作用.
在丹麦,当我们为产品写价格时,我们使用符号19,95而不是美国19.95的方式,这给了我一个问题,我无法解决.
我已经启动了VS2010,新的MVC 3项目,添加了一个homeController,一个Product类和一个简单的标准编辑视图,错误已经存在.
产品类别:
public class Product
{
public string name { get; set; }
public string itemNo { get; set; }
public decimal price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
HomeController的:
public class homeController : Controller
{
public ActionResult Index()
{
var product1 = new Product { name = "Testproduct", itemNo = "PRD-151541", price = 19 };
return View(product1);
}
}
Run Code Online (Sandbox Code Playgroud)
索引视图:
@model WebUI.DomainModel.Product
<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>Product</legend>
<div class="editor-label"> …Run Code Online (Sandbox Code Playgroud) 我一直在扫描,试图找到一个合适的解决方案,为主页面中的菜单项分配"活动/当前"类.关于是否执行此客户端与服务器端,该线路在中间分开.
说实话,我是JavaScript和MVC的新手,所以我没有意见.我更愿意以"最干净"和最恰当的方式做到这一点.
我有以下jQuery代码将"活动"类分配给<li>项...唯一的问题是"索引"或默认视图菜单项将始终分配活动类,因为URL始终是子字符串其他菜单链接:
(default) index = localhost/
link 1 = localhost/home/link1
link 2 = localhost/home/link1
$(function () {
var str = location.href.toLowerCase();
$('#nav ul li a').each(function() {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$(this).parent().attr("class","active"); //hightlight parent tab
}
});
Run Code Online (Sandbox Code Playgroud)
伙计们,有更好的方法吗?有人至少会帮助我获得客户端版本的防弹吗?那么"索引"或默认链接总是"活跃"?有没有办法为索引方法分配假扩展?喜欢而不仅仅是基本URL localhost/home/dashboard,它不会是每个链接的子串?
说实话,我并没有真正遵循做这个服务器端的方法,这就是为什么我试图用jQuery做客户端...任何帮助将不胜感激.
我正在寻找通过JSON将对象数组发布到MVC3的解决方案.
我正在处理的示例代码:http: //weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx
JS:
var data = { ItemList: [ {Str: 'hi', Enabled: true} ], X: 1, Y: 2 };
$.ajax({
url: '/list/save',
data: JSON.stringify(data),
success: success,
error: error,
type: 'POST',
contentType: 'application/json, charset=utf-8',
dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)
ListViewModel.cs:
public class ListViewModel
{
public List<ItemViewModel> ItemList { get; set; }
public float X { get; set; }
public float Y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
ItemViewModel.cs:
public class ItemViewModel
{
public string Str; // originally posted with: { get; …Run Code Online (Sandbox Code Playgroud) 我想创建一个扩展方法HtmlHelper,允许我创建LabelFor一个属性显示后面的星号,如果它是必填字段.我怎样才能做到这一点?
public class Foo
{
[Required]
public string Name { get; set; }
}
Html.LabelFor(o => o.Name) // Name*
Run Code Online (Sandbox Code Playgroud) 我试图通过使用Viewbag将表单元素传递到MVC3视图,并简单地将HTML写入页面...
在控制器中:
ViewBag.myData = "<input type=""hidden"" name=""example"" value=""examplevalue"">";
Run Code Online (Sandbox Code Playgroud)
在视图中(我知道我可以使用表单的帮助器):
<form action="http://exampleurl/examplepage" method="post" id="example-form">
@ViewBag.myData
<input type="hidden" name="anotherexample" value="anotherexamplevalue" />
</form>
Run Code Online (Sandbox Code Playgroud)
这将myData呈现为HTML中的文本,即:
<type="hidden" name="example" value="examplevalue">
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我如何让Razor做相当于旧的:
<%= myData %>
Run Code Online (Sandbox Code Playgroud)
而不是取代<>
谢谢保罗
我想在编辑页面中使用EditorFor进行readOnly.
我尝试将readonly和disabled设置为:
<div class="editor-field">
@Html.EditorFor(model => model.userName, new { disabled = "disabled", @readonly = "readonly" })
</div>
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.如何禁用编辑此字段?
谢谢.
Required像这样使用数据注释:
[Required]
public int somefield {get; set;}
Run Code Online (Sandbox Code Playgroud)
将somefield设置为Not Null数据库,如何设置某个字段
以允许NULL?,我尝试通过SQL Server Management Studio设置它,但实体框架将其设置回Not Null.
当我尝试渲染其模型类型指定为的部分视图时:
@model dynamic
Run Code Online (Sandbox Code Playgroud)
使用以下代码:
@{Html.RenderPartial("PartialView", Model.UserProfile);}
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'RenderPartial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Run Code Online (Sandbox Code Playgroud)
但是,.aspx文件中的相同代码完美无瑕.有什么想法吗?
传递给View的模型有一个奇怪的问题
调节器
[Authorize]
public ActionResult Sth()
{
return View("~/Views/Sth/Sth.cshtml", "abc");
}
Run Code Online (Sandbox Code Playgroud)
视图
@model string
@{
ViewBag.Title = "lorem";
Layout = "~/Views/Shared/Default.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
错误消息
The view '~/Views/Sth/Sth.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Sth/Sth.cshtml
~/Views/Sth/abc.master //string model is threated as a possible Layout's name ?
~/Views/Shared/abc.master
~/Views/Sth/abc.cshtml
~/Views/Sth/abc.vbhtml
~/Views/Shared/abc.cshtml
~/Views/Shared/abc.vbhtml
Run Code Online (Sandbox Code Playgroud)
为什么我不能将简单的字符串作为模型传递?
在每个人都读到这篇文章之前,我只是想说我知道那里有相关的主题,但我要么尝试过,要么不明白.据说这里什么都没有......
我想在我的IIS中运行一个MVC Web App.不幸的是,我完全坚持这个错误:
HTTP Error 500.19 - Internal Server Error
The Request page cannot be accessed becasue the related configuration data for
the page is invalid.
Module: IIS Web Core
Notification: BeginRequest
Handler: Not yet determined
Error Code: 0x80070005
Config Error: Cannot read configuration file due to insufficient permissions
Config File: \foo\web.config
Request URL: http://localhost/WEBAPP
Logon Method: Not yet determined
Logon User: Not yet determined
Config Source
-1:
0:
Run Code Online (Sandbox Code Playgroud)
我不太清楚还能做什么.我也试过给web.config文件提供读取权限,但似乎没有用.
如果有人有任何信息或能够帮助我完成这项工作,我将不胜感激.谢谢!
asp.net-mvc-3 ×10
asp.net-mvc ×4
c# ×2
razor ×2
arrays ×1
code-first ×1
culture ×1
editorfor ×1
html ×1
iis-7 ×1
jquery ×1
json ×1
master-pages ×1
menu ×1
nullable ×1
post ×1
readonly ×1
validation ×1
viewbag ×1