在列出控制器我有,
public ActionResult GetByList(string name, string contact)
{
var NameCollection = Service.GetByName(name);
var ContactCollection = Service.GetByContact(contact);
return View(new ListViewModel(NameCollection ,ContactCollection));
}
Run Code Online (Sandbox Code Playgroud)
在ASPX页面我打电话,
<a href="<%:Url.Action("GetByList","Listing" , new {name= "John"} , new {contact="calgary, vancouver"})%>"><span>People</span></a>
Run Code Online (Sandbox Code Playgroud)
我在ASPX代码中遇到问题...我可以提取名称为john的记录.但当我给联系人="卡尔加里,温哥华"时,网页会出错.
如何在Url.Action中调用两个参数.我尝试了以下但这似乎也错了.
<a href="<%:Url.Action("GetByList","Listing" , new {name= "John" , contact= " calgary, vancouver" })%>"><span>People</span></a>
Run Code Online (Sandbox Code Playgroud) 我刚刚升级到Visual Studio 2010和MVC 2.0,我注意到Web.config附加了两个附加文件?这些文件是否用于指定调试和发布特定设置,因此您不会混淆主Web.config?
如果在调试和发布Web.configs中分别有本地和远程连接字符串,那么在根Web.config文件中放置连接字符串是否有意义?
谢谢!
asp.net asp.net-mvc web-config visual-studio-2010 asp.net-mvc-2
我正在尝试开始使用ASP.NET MVC Ajax调用.
控制器:
public class AjaxTestController : Controller
{
//
// GET: /AjaxTest/
public ActionResult Index()
{
return View();
}
public ActionResult FirstAjax()
{
return Json("chamara", JsonRequestBehavior.AllowGet);
}
}
Run Code Online (Sandbox Code Playgroud)
视图:
<head runat="server">
<title>FirstAjax</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var serviceURL = '/AjaxTest/FirstAjax';
$.ajax({
type: "POST",
url: serviceURL,
data: param = "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
alert(data);
}
function errorFunc() {
alert('error');
}
});
</script>
</head> …Run Code Online (Sandbox Code Playgroud) 在ASP.NET MVC2中我使用OutputCache和VaryByParam属性.我用一个参数就可以正常工作,但是当我在方法上有几个参数时,正确的语法是什么?
[OutputCache(Duration=30, VaryByParam = "customerId"]
public ActionResult Index(int customerId)
{
//I've got this one under control, since it only has one parameter
}
[OutputCache(Duration=30, VaryByParam = "customerId"]
public ActionResult Index(int customerId, int languageId)
{
//What is the correct syntax for VaryByParam now that I have a second parameter?
}
Run Code Online (Sandbox Code Playgroud)
如何使用这两个参数来缓存页面?我输入两次添加属性吗?或者写"customerId,languageId"作为值?
虽然我已经阅读了关于Html.HiddenFor的文档,但我还没有理解它用于...
有人可以解释它的用途并举一个简短的例子吗?
这些助手应该在哪里进入代码?
好的,我一直听到有关MS的ASP.NET MVC的"ViewModels"的讨论.
现在,这是一种特定的模型,对吗?不是特定的视图.
根据我的理解,它是一种具有与View交互的特定目的的模型?或类似的东西?
一些澄清将不胜感激.
我想要一个单独的动作响应获取和帖子.我尝试了以下内容
[HttpGet]
[HttpPost]
public ActionResult SignIn()
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.有什么建议 ?
作品
<a href="@Url.Action("edit", "markets", new { id = 1 })"
data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>
Run Code Online (Sandbox Code Playgroud)
不工作 - 为什么?
@Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"})
Run Code Online (Sandbox Code Playgroud)
看来你不能把像data-icon ="gear"这样的东西传递给htmlAttributes?
建议?
我可以用[AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)]装饰一个动作
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(string title)
{
// Do Something...
}
Run Code Online (Sandbox Code Playgroud)
或者使用[HttpPost]/[HttpGet]属性
[HttpPost]
public ActionResult Create(string title)
{
// Do Something...
}
Run Code Online (Sandbox Code Playgroud)
他们不一样吗?
如何在ASP.NET MVC和C#中实现reCaptcha?
asp.net-mvc-2 ×10
asp.net-mvc ×7
asp.net ×4
c# ×2
.net ×1
actionlink ×1
html ×1
html-helper ×1
http-get ×1
http-post ×1
jquery ×1
model ×1
outputcache ×1
url.action ×1
viewmodel ×1
web-config ×1