Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery设置asp.net mvc模型值_Javascript_Jquery_Asp.net Mvc 4 - Fatal编程技术网

Javascript 使用jquery设置asp.net mvc模型值

Javascript 使用jquery设置asp.net mvc模型值,javascript,jquery,asp.net-mvc-4,Javascript,Jquery,Asp.net Mvc 4,我的理解有差距。我有两个视图屏幕,一个成功地从devexpress选择网格中获取值,但另一个没有。。。我不明白我在做什么不同 当我使用firebug时,我找不到模型在DOM中的设置位置 以下工作: using System; using System.Collections.Generic; using System.Linq; using System.ComponentModel.DataAnnotations; namespace EtracsWeb.Areas.IO.Models {

我的理解有差距。我有两个视图屏幕,一个成功地从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>
@使用EtracsWeb.Areas.IO.Models;
@模型航行输入模型
@{
ViewBag.Title=“航行(接收/未接收/等)”;
Layout=“~/Views/Shared/_LayoutMenu.cshtml”;
}
@*必须在这里,而不是在结尾,否则代码将无法工作*@
//这是devExpress选择网格中的值。。。
功能选择已更改(s、e){
s、 GetSelectedFieldValues(“VoyageID”,GetSelectedFieldValuesCalback);
}
//这是来自InputModel的值…请注意,它是不同的。。。
//这就是为什么我们需要这两个步骤。
函数GetSelectedFieldValuesCalback(值){
//航次=数值;
//警报(数值);
document.getElementById('VoyageIDS')。值=值;
//警报(document.getElementById('VoyageIDS').value)
}
请注意,我从OnSelection中获取的值被更改为一个变量,并在inputModel中设置为不同的名称…这一切都有效

我尝试使用第二个视图来执行此操作,但代码在我尝试使用getElementbyID访问模型中的变量时终止。。。。最初我尝试使用int…但我将其切换为字符串…但两者都不起作用

DOM中的模型到底在哪里?如何使用Firebug查看@model值(来自asp.net mvc)

知道我在第二个窗口哪里出错了吗

以下是第二个inputmodel:

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; }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.ComponentModel.DataAnnotations;
命名空间EtracsWeb.Areas.Vehicle.Models
{
公共类BookMarkListInputModel
{
公共字符串SelectedBookMarkID{get;set;}
public int bookmark id{get;set;}
公共IEnumerable书签{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>
@使用EtracsWeb.Areas.Vehicle.Models
@模型书签ListInputModel
@{
ViewBag.Title=“列表”;
Layout=“~/Views/Shared/_LayoutMenu.cshtml”;
}
@*必须在这里,而不是在结尾,否则代码将无法工作*@
//这是在DevExpress选择网格中使用的值
功能选择已更改(s、e){
s、 GetSelectedFieldValues(“书签ID”,GetSelectedFieldValuesCalback);
}
//这是来自InputModel的变量…请注意,它可能不同
//所以我们需要有两个步骤。
函数GetSelectedFieldValuesCalback(值){
警报(数值);
document.getElementById('SelectedBookMarkID')。值=值;
警报(document.getElementById('SelectedBookMarkID')。值)
}
功能成功(数据){
//警报(数据返回消息);
id1.innerHTML=data.ReturnMessage;
}

没有“DOM中的模型在哪里”这样的东西。DOM包含视图中的HTML元素。我认为您需要阅读更多关于ASP.Net和MVC的内容。好吧……但是在调试中……模型值来自哪里。。。我看过asp.net类…但是有很多…这里很难解释。您需要阅读有关MVC和ASP.Net的一般知识。可能会得到一些教程,例子等。你只是没有得到框架的工作方式。好的,我会看看这个。谢谢