我想在每次单击ActionLink时更新局部视图.我将相同的模型作为主视图传递给局部视图.问题是部分视图没有得到更新.不确定我是否在正确的轨道上.
查看:
@model MyPoll.Models.Poll
@Ajax.ActionLink("For", "AddPositive", new RouteValueDictionary { {"id", Model.Id }},new AjaxOptions() { UpdateTargetId = "countsDiv" })
<div id="countsDiv">
@Html.Partial("Counts", Model)
</div>
Run Code Online (Sandbox Code Playgroud)
部分:
@model MyPoll.Models.Poll
Positive count : @Model.PositiveCount
Negative count : @Model.NegativeCount
Run Code Online (Sandbox Code Playgroud)
控制器动作:
public ActionResult AddPositive(int id)
{
Poll poll = db.Polls.Find(id);
poll.PositiveCount++;
db.SaveChanges();
return View(poll);
}
Run Code Online (Sandbox Code Playgroud)
脚本也被引用:
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud) 新的MVC4应用程序创建了UserProfile表:
UserId(int)| 用户名(NVARCHAR)
在控制器中:
string currentUser = User.Identity.Name; // returns UserName
var mu1 = Membership.GetUser(); // returns null
var mu2 = Membership.GetUser(currentUser); // returns null as well
Run Code Online (Sandbox Code Playgroud)
我读了很多帖子,他们都谈到了获取Guid,我甚至没有在用户和会员表中.
有没有办法获取当前登录用户的UserId(int)?
我在StackOverflow上有类似的帖子,但也许我的误解更为重要.我有一个动作索引()和索引视图的渲染.从Index()视图取决于单击的按钮[HttpPost]索引()或[HttpPost] Search()必须被调用因为我发布了一些数据.发布到不同操作的唯一方法是使用jQuery吗?如果jQuery是唯一的方法,如果我的操作返回视图(完整的Html页面),我必须从$ .post清理整个文档元素并用我的视图html填充它?我对这一切都很陌生,非常感谢!
@using (Html.BeginForm())
{
<input name="startDate" type="text" size="20" class="inputfield" id="datepicker" />
<a href="#" id="apply_button">...</a>
<a href="#" id="go_button">...</a>
}
public ActionResult Index(string lang)
{
return View();
}
//Perhaps this action is needed
[HttpPost]
public ActionResult Index(string lang, string startDate)
{
return View();
}
[HttpPost]
public ActionResult Search(string lang, string startDate)
{
return View();
]
Run Code Online (Sandbox Code Playgroud) 垂直对齐:中间; 不管用.
From css file :
#header {height:150px; text-align: center; vertical-align: middle;}
<div id="header">
<img alt="" id="logo" src="images/logo.png" />
</div>
Run Code Online (Sandbox Code Playgroud)
如果它有助于将徽标与包装div的中心对齐,我会将徽标包装在另一个div中.
我正在阅读关于TypeScript的Pluralsight课程,这会引发错误,同时它被解释为课程中的有效代码.
错误TS2322:输入'{favouriteSport:string; name:string; 孩子:数量; 年龄:数量; calcPets :()=>数字; makeYo ...'不能指定为'Person'类型.对象文字只能指定已知属性,'person'类型中不存在'favouriteSport'.
interface Person{
age: number,
name: string,
kids: number,
calcPets: ()=> number;
makeYounger: (years: number) => void;
greet: (msg: string) => string;
}
var p: Person = {
favouriteSport: "tennis",
name: "Michael",
kids: 4,
age: 44,
calcPets: function(){
return this.kids * 2;
},
makeYounger: function(years: number){
this.age -= years;
},
greet: function(msg: string){
return msg + ', ' + this.name;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个1905像素宽的图像,我希望自动调整大小以适应引导程序读取的宽度.这似乎不起作用:
<div class="body container-fluid">
<div class="row">
<div class="col-md-12 col-lg-12 col-sm-12">
<img src="~/Content/Images/Temp/WP_20140326_001.jpg" />
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我必须使用CSS宽度吗?谢谢 !
它从cmd开始,但调试时不会进入condiion,任何想法为什么请?在IIS中浏览该站点将返回异常: System.ComponentModel.Win32Exception:拒绝访问.
string video;
string thumb;
video = System.Web.HttpContext.Current.Server.MapPath("Video/test.avi");
thumb = System.Web.HttpContext.Current.Server.MapPath("Video/frame.jpg");
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = System.Web.HttpContext.Current.Server.MapPath("Video/ffmpeg.exe"),
Arguments = " -i " + video + " -ss 00:00:03 -vframes 1 -f image2 -vcodec mjpeg " + thumb,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
}
Run Code Online (Sandbox Code Playgroud) 我需要创建一个选择列表,保留状态,这不是传递给视图的模型的一部分.我想我应该使用ViewBag将List传递给View?有关实现的任何建议以及如何保留选择列表的状态(如何将选定的值再次传递给操作和视图(可能的方法)?
截至目前的行动:
public ActionResult Images(string x, string y)
{
//some code
ContentPage cp = this.ContentPage;
return View(cp);
}
//Post to action with same name:
[HttpPost]
public ActionResult Images(string someParameter)
{
ContentPage cp = this.ContentPage;
return View(cp);
}
Run Code Online (Sandbox Code Playgroud)
截至目前的观点:
@model ContentPage
@{
ViewBag.Title = "Images";
CmsBaseController controller = (this.ViewContext.Controller as CmsBaseController);
}
@using (Html.BeginForm())
{
<div>
//This should go to List<SelectListItem> as I understand
<select name="perpage" id="perpage" onchange='submit();'>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
}
Run Code Online (Sandbox Code Playgroud)
谢谢!!!
我在某些代码中找到了以下代码:
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
Run Code Online (Sandbox Code Playgroud)
Resharper正在使ToString()通话变得灰暗,这一直是一个很好的建议.没有它,这个C#代码如何工作?会ToString()隐含调用吗?
我有一个div与css水平居中:
.bar {
height: 38px;
width: 970px;
margin-left: auto;
margin-right: auto;
}
Run Code Online (Sandbox Code Playgroud)
我需要有另一个元素从右边有相同的边距作为.bar,所以我使用jQuery大小:
<div class="spec">I need to be aligned the same.</div>
Run Code Online (Sandbox Code Playgroud)
JS:
$(".spec").css('margin-right', $('.bar').margin().right + 'px');
Run Code Online (Sandbox Code Playgroud)
这有效,但在Firefox 30.0中没有,因为它为.bar的计算margin-right 返回0.有什么建议 ?http://jsbin.com/difobu/1/edit.
$('.bar').css('margin-right')也在FF 30.0中返回0px. 如果您投票,请提供解释.
css ×3
asp.net ×2
asp.net-mvc ×2
c# ×2
jquery ×2
ajax ×1
firefox ×1
html ×1
javascript ×1
margin ×1
membership ×1
posting ×1
resharper ×1
selectlist ×1
thumbnails ×1
tostring ×1
typescript ×1
video ×1