我有这样的链接:
<a href='Member/MemberHome/Profile/Id'><span>Profile</span></a>
Run Code Online (Sandbox Code Playgroud)
当我点击它时,它会调用这个部分页面:
@{
switch ((string)ViewBag.Details)
{
case "Profile":
{
@Html.Partial("_Profile"); break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
部分页面_Profile包含:
Html.Action("Action", "Controller", model.Paramter)
Run Code Online (Sandbox Code Playgroud)
例:
@Html.Action("MemberProfile", "Member", new { id=1 }) // id is always changing
Run Code Online (Sandbox Code Playgroud)
我怀疑的是我如何将这个"Id"传递给model.parameter部分?
我的控制器是:
public ActionResult MemberHome(string id)
{
ViewBag.Details = id;
return View();
}
public ActionResult MemberProfile(int id = 0)
{
MemberData md = new Member().GetMemberProfile(id);
return PartialView("_ProfilePage",md);
}
Run Code Online (Sandbox Code Playgroud) 在安装然后修复我的VS2015实例后,我仍然无法让智能感知(服务器端)在我的MVC视图中工作.我第一次在会话中打开一个.cshtml文件时会收到消息提示,然后发送到Activitylog文件.在ActivityLog.xml(简短版本)中检索到错误消息:
System.ArgumentException:已添加项目.词典中的关键词:'RazorSupportedRuntimeVersion'
这是完整版:
System.Reflection.TargetInvocationException:调用目标抛出了异常.---> System.ArgumentException:已添加项目.词典中的关键词:'RazorSupportedRuntimeVersion'重点正在补充说:"RazorSupportedRuntimeVersion"在System.Collections.Hashtable.Insert(对象键,对象n值,布尔加)在System.Collections.Hashtable.Add(对象键,对象值)System.Collections.Specialized.HybridDictionary.Add在Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(对象键,对象属性)在Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector(对象键,对象的值) .GetVersion(ITextBuffer textBuffer)at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer,Version&razorVersion)at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer)--- End内部异常堆栈跟踪---在System.System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr)中的System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)中的RuntimeMethodHandle.InvokeMethod(Object target,Object []参数,Signature sig,Boolean构造函数) System.Activator.CreateInstance(Type type,BindingFlags bindingAttr,Binder binder,Object [] args,CultureInfo culture,Object [] activationAttributes)at,Binder binder,Object [] args,CultureInfo culture,Object [] activationAttributes,StackCrawlMark&stackMark) Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator'中的Microsoft.Html.Editor.ContainedLanguage.Common.ContainedCodeErrorTaggerProvider'1.CreateTagger [T](ITextBuffer textBuffer)中的System.Activator.CreateInstance(Type type,Object [] args)1.GatherTaggers(ITextBuffer textBuffer)
如果有任何帮助,我会进行一些字体着色自定义,并安装Web Essentials,Bundler和Minifier以及Web编译器扩展.
更新:当我打开现有的Web应用程序或从头开始创建一个全新的Web应用程序时,它就会发生.还有一个VS2013的实例在同一台机器上安装并运行.
正如你从上面的图片中看到的那样,我根本没有智能感知,也没有任何代码着色.
有关如何解决它的任何线索?提前致谢.
在默认的ASP.NET MVC 3项目中,布局和部分cshtml文件以下划线开头
_viewstart_Layout_LogOnPartial为什么这个惯例,这是用来做什么的?我需要遵循这个惯例吗?
框架是否为以.cshtml下划线开头的文件赋予了一些特殊含义?
虽然微软在剃刀MVC4中创建了一些html属性的自动渲染,但我花了很长时间才找到如何基于条件剃刀表达式在元素上渲染第二个css类.我想和你分享.
基于模型属性@ Model.Details,我想显示或隐藏列表项.如果有细节,则应显示div,否则应隐藏.使用jQuery,我需要做的就是分别添加一个类show或hide.出于其他目的,我还想添加另一个类"详细信息".所以,我的加价应该是:
<div class="details show">[Details]</div> 要么 <div class="details hide">[Details]</div>
下面,我展示了一些失败的尝试(假设没有细节,导致标记).
这:<div @(@Model.Details.Count > 0 ? "class=details show" : "class=details hide")>,
会这样:<div class="details" hide="">.
这个:<div @(@Model.Details.Count > 0 ? "class=\"details show\"" : "class=\"details hide\"")>.
会这样:<div class=""details" hide"="">.
这个: <div @(@Model.Details.Count > 0 ? "class='details show'" : "class='details hide'")>
会这样:<div class="'details" hide'="">.
这些都不是正确的标记.
如何在cshtml文件中为J2变量渲染布尔值?
目前,这显示语法错误:
<script type="text/javascript" >
var myViewModel = {
isFollowing: @Model.IsFollowing // This is a C# bool
};
</script>
Run Code Online (Sandbox Code Playgroud) 如果我这样写:
form action ="Images"method ="post"enctype ="multipart/form-data"
有用.
但是在使用'@'的Razor中,它不起作用.我犯了什么错误吗?
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
Select a file <input type="file" name="file" />
<input type="submit" value="Upload" />
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Upload()
{
foreach (string file in Request.Files)
{
var uploadedFile = Request.Files[file];
uploadedFile.SaveAs(Server.MapPath("~/content/pics") +
Path.GetFileName(uploadedFile.FileName));
}
return RedirectToAction ("Upload");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建DropDownList一个剃刀视图.
有人会帮我这个吗?
普通的HTML5代码:
<select id="dropdowntipo">
<option value="Exemplo1">Exemplo1</option>
<option value="Exemplo2">Exemplo2</option>
<option value="Exemplo3">Exemplo3</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
@{
var listItems = new List<ListItem> {
new ListItem { Text = "Exemplo1", Value = "Exemplo1" },
new ListItem { Text = "Exemplo2", Value = "Exemplo2" },
new ListItem { Text = "Exemplo3", Value = "Exemplo3" }
};
}
@Html.DropDownListFor(model =>
model.tipo,
new SelectList(listItems),
"-- Select Status --"
)
Run Code Online (Sandbox Code Playgroud) 如何在视图或控制器中获取当前区域名称?
ViewContext.RouteData.Values["controller"]区域有什么吗?
在我的cshtml文件中,我有很多块,有这样的东西:
@if(Model.foo)
{
<span>Hello World</span>
}
Run Code Online (Sandbox Code Playgroud)
跨度的唯一原因是因为我找不到任何其他方法来强制它识别"Hello World"是html的一部分,除非我将它包围在html标签中.是否有一种很好的方法来逃避不涉及向显示器添加无意义标签的代码?
我的MVC表单上有两个按钮:
<input name="submit" type="submit" id="submit" value="Save" />
<input name="process" type="submit" id="process" value="Process" />
Run Code Online (Sandbox Code Playgroud)
从我的Controller动作我怎么知道哪一个被按下了?