我的理解存在差距。我有两个视图屏幕,一个成功从一个devexpress选择网格获得一个值,但是一个没有...而且我不明白我在做什么不同。
当我使用firebug时,我找不到在DOM中设置模型的位置。
以下作品:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;
namespace EtracsWeb.Areas.IO.Models
{
public class VoyageInputModel
{
[Required(ErrorMessage = "Value must be supplied")]
[Display(Name = "Show Received Voyages")]
public bool ShowReceivedVoyages { get; set; }
public string VoyageIDS { get; set; }
}
}
在视图中使用(有效)...这里是视图的一个片段:
@using EtracsWeb.Areas.IO.Models;
@model VoyageInputModel
@{
ViewBag.Title = "Voyage (Receive/UnReceive/etc..)";
Layout = "~/Views/Shared/_LayoutMenu.cshtml";
}
@* MUST go here and NOT at end or code won't work *@
<script type="text/javascript">
//This is the value from the devExpress Selection Grid...
function OnSelectionChanged(s, e) {
s.GetSelectedFieldValues("VoyageID", GetSelectedFieldValuesCallback);
}
//This is the value from the InputModel...notice it is different...
//This is why we need this two step process.
function GetSelectedFieldValuesCallback(values) {
// voyage_ids = values;
//alert(values);
document.getElementById('VoyageIDS').value = values;
//alert(document.getElementById('VoyageIDS').value)
}
</script>
注意我将OnSelection中的值更改为一个变量,并将inputModel中的值设置为不同的名称....这一切都有效......
我正在尝试使用第二个视图并且代码在我尝试使用getElementbyID来访问模型中的变量时死亡....最初我试图使用int ...但我将其切换为一根绳子......但是都没有工作......
在哪里,DOM中的模型?如何使用Firebug查看@model值(来自asp.net mvc)???
我在第二个窗口出错的任何想法?
这是第二个输入模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;
namespace EtracsWeb.Areas.Vehicle.Models
{
public class BookMarkListInputModel
{
public string SelectedBookMarkID { get; set; }
public int BookMarkID { get; set; }
public IEnumerable<BookMark> BookMarks { get; set; }
}
}
和第二个视图片段:
@using EtracsWeb.Areas.Vehicle.Models
@model BookMarkListInputModel
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/_LayoutMenu.cshtml";
}
@* MUST go here and NOT at end or code won't work *@
<script type="text/javascript">
//This is the value used in the DevExpress Selection Grid
function OnSelectionChanged(s, e) {
s.GetSelectedFieldValues("BookMarkID", GetSelectedFieldValuesCallback);
}
//This is the variable from the InputModel...notice it can be different
//So we need to have this two step process.
function GetSelectedFieldValuesCallback(values) {
alert(values);
document.getElementById('SelectedBookMarkID').value = values;
alert(document.getElementById('SelectedBookMarkID').value)
}
function Success(data) {
// alert(data.ReturnMessage);
id1.innerHTML = data.ReturnMessage;
}
</script>