帮助MVC应用程序 [英] Help with MVC application
问题描述
嘿伙计们,我正在学习为微软做MVC4考试,我正在努力解决一个小问题。我正在尝试重新创建一个旧的项目,我在MVC的Web表单中做了一段时间,证明它很难。好吧我的问题,我有一堆javascript文件,寻找一个id为日历的div并创建一个日历控件,无论我在MVC中尝试什么我都无法让它工作但在Web表单中它的工作原理就像一个对待。所以我试图访问Index.cshtml文件中的Calendar div,但无论我尝试什么,我总是得到不明确的
_Layout.cshtml
Hey guys, I'm studying to do the MVC4 exam for Microsoft and im running in to a little issue. I'm trying to re-create an old project I done a while back in Web forms in MVC and its proving rather difficult. Ok my problem, I have a bunch of javascript files which look for a div with an id of calender and create a calender control, No matter what I try in MVC I can't get it to work but in Web forms it works like a treat. So I'm trying to access the Calendar div in the Index.cshtml file but no matter what I try I always get underfined
_Layout.cshtml
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/jquery-ui.min.css")
@Styles.Render("~/Content/fullcalendar.css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jquery-2.1.0.js")
@Scripts.Render("~/Scripts/jquery-ui-1.10.4.js")
@Scripts.Render("~/Scripts/fullcalendar.js")
@Scripts.Render("~/Scripts/jquery-ui.custom.min.js")
@Scripts.Render("~/Scripts/Calendar.js")
</head>
Index.cshtml
Index.cshtml
<pre lang="xml">@{
ViewBag.Title = "Calendar";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Calendar</h2>
<div id="calendar"></div></pre>
Calendar.js
Calendar.js
var calendar = $('#calendar');
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
所以在Calendar.js我当我尝试访问日历div时总是得到定义。
任何帮助都是非常苛刻的,记住我到目前为止开发的所有内容都是web表单所以如果它的东西愚蠢我很遗憾:)。
So in Calendar.js I always get underfined when I try to access the calendar div.
Any help is very much apreciated, bearing in mind that all I have developed in thus far is web forms so if its something silly im missing be nice :).
推荐答案
('#calendar');
var calendar =
('#calendar'); var calendar =
('#calendar')。fullCalendar({
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' },
因此,在Calendar.js中,当我尝试访问日历div时,我总是被定义为。
任何帮助都是非常苛刻的,请记住所有到目前为止,我已经开发了Web表单,所以如果它缺少的东西很好看:)。
So in Calendar.js I always get underfined when I try to access the calendar div.
Any help is very much apreciated, bearing in mind that all I have developed in thus far is web forms so if its something silly im missing be nice :).
你必须加载 @ Scripts.Render(〜/ Scripts / Calendar Index.cshtml 中的.js)。从 _Layout.cshtml 中删除它。试一试。
You have to load @Scripts.Render("~/Scripts/Calendar.js") inside your Index.cshtml.Remove it from the _Layout.cshtml .Try it.
这篇关于帮助MVC应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!