如何通过单击使用EF从右侧更改数据 [英] How to Change Data from the right side to the left by clicking using EF

查看:100
本文介绍了如何通过单击使用EF从右侧更改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过使用实体框架正确点击从右侧到左侧的数据。数据是西班牙语,对不起,但是我不能改变它。

I want to know how can I change my data from the right side to the left by clicking correctly using Entity Framework. The data is in spanish, sorry for that but I can´t change it.

这是我的视图,我只能改变Titulo,这意味着在扩大标题和内容,但我有我的DateTime和我的图像成为一个相关的表和int数据的问题。 Id更改,因为它显示在右侧(我不想在右侧显示图像和Id数据)。

Here is my View where I can only change the "Titulo" that means in enlgish Title and the Content but I have problem with my DateTime and my Images that become a related table and with int data. The Id change because it appears in the right side (I dont want to show the Image and Id data in the right side).

显示主要图像我使用这个 @foreach 在那里我从第二个获取数据表名为Noticias1,这意味着英文News1每个新闻的图像数据在哪里, if(img!= null&& img.Nombre.Equals(@principalId +_ 0)) code>只显示等于所选Id的Principal Img(我将在内容中显示其他Img)。

To show the principal Image I use this @foreach where I get the data from the second table called "Noticias1" that means in english News1 where are the Image data for every News and if (img != null && img.Nombre.Equals(@principalId+"_0")) to show me only the Principal Img that is equal to the selected Id (I will show the others Img behind the content.)

这里的代码

@foreach (var n in Model) 
{
  var img = n.Noticias2.FirstOrDefault(); 
  if (img != null && img.Nombre.Equals(@principalId+"_0")) 
  {
    var imgRuta = @img.Ruta+@img.Nombre+@img.Extension; 
    <img id="currentprincipalImagen" src="@imgRuta" class="img-responsive" alt="Imagen de Marte" />
    <figcaption>
      <p id="currentPrincipalImagenTitulo">@img.Descripcion</p>
    </figcaption>
   }
}

这是我的完整视图代码

@{
    var format = "dddd, MMMM dd, yyyy"; 
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    int principalId = Model[0].IdNoticia; 
    string principalTitulo = Model[0].Titulo; 
    string principalContenido = Model[0].Contenido;
    DateTime principalFechaDesde = Convert.ToDateTime(Model[0].FeDesde);
    DateTime principalFechaHasta = Convert.ToDateTime(Model[0].FeHasta);
}

<script type="text/javascript">
    function changeDisplay(e) {

        var principalTitulo = $(e).text(); 
        var principalContenido = $(e).siblings(".Contenido:first").html(); 
        var principalId = $(e).siblings(".IdNoticia:first").html();
        var principalFechaDesde = $(e).siblings(".FeDesde").html();


        $("#currentprincipalTitulo").html(principalTitulo);
        $("#currentprincipalContenido").html(principalContenido);
        $("#currentprincipalId").html(principalId);
        $("#currentprincipalFechaDesde").html(principalFechaDesde);
    }
</script>

<!-- Principal -->
<div class="col-md-12 main">

    <div class="header sec-title-hd">
        <div class="bg-calendar"></div>
        <div class="col-md-7">
            <h5 class="pull-left">NOTICIAS</h5>
            <div>
                <a href="dashboard.html" class="btn sky-blue n-radius-b"> <img src="slider/img/arrow-left.png"> VOLVER</a>
            </div>
        </div>
    </div>

    <div class="content-inter">
        <div class="container-fluid sec-title-hd-sub">
            <div class="row">
                <div class="col-md-7">
                    <div>
                        <figure class="img_N">
                            @foreach (var n in Model) 
                            {
                                var img = n.Noticias2.FirstOrDefault(); 
                                if (img != null && img.Nombre.Equals(@principalId+"_0")) 
                                {
                                    var imgRuta = @img.Ruta+@img.Nombre+@img.Extension; 
                                    <img id="currentprincipalImagen" src="@imgRuta" class="img-responsive" alt="Imagen de Marte" />
                                    <figcaption>
                                        <p id="currentPrincipalImagenTitulo">@img.Descripcion</p>
                                    </figcaption>
                                }
                            }
                        </figure>
                    </div>
                    <div class="textnota">
                        <br>
                        <h6 id="currentprincipalId">@principalId</h6>
                        <h5 id="currentprincipalTitulo" class="titulo_N uppercase">@principalTitulo</h5>
                        <p id="currentprincipalFechaDesde" class="time">FeDesde: @principalFechaDesde.ToString(format)</p> 
                        <div class="noti_P">
                            <p id="currentprincipalContenido">@principalContenido</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-5">
                    <!-- Right Side -->
                    @foreach (var n in Model)
                    {

                        <blockquote class="blockquote-nopadding bg-calendar-border-left">
                            <h6 class="IdNoticia">@n.IdNoticia</h6>
                            <p class="time_f feDesde">@n.FeDesde.ToString(format)</p>
                            <a href="#" onclick="changeDisplay(this)" class="titulo_N">@n.Titulo</a>
                            <p class="text-justify limit Contenido">@n.Contenido</p>
                        </blockquote>
                    }
                    Págnia @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) de @Model.PageCount
                    @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
                    <div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

谢谢。我知道在我的Jquery脚本代码中,我没有什么可以改变图像,但是我删除了这个,因为我无法做到这一点,将Id更改为左边的 @foreach 一边改变我的主要形象。我的英文不好,我希望你能理解我。

Thanks. I know that in my Jquery Script code I dont have something to change the Image but I remove this because I cant do the relation to change the Id into the @foreach in the left side to changue my principal Image. my english is not good I hope you could understand me.

这里是关系,如果我点击了第一个Id = 1我想从该Id获取图像与Id = 2,3,4 ...相同。

Here is the relation where If I click the first with Id = 1 I want to get the images from that Id and the same with Id = 2, 3, 4...

推荐答案

我发现自己的解决方案,问题出在我的Jquery代码中。也许这不是在实体框架中做的最好的方法,但这是我如何解决这个问题。 (如果您有更好的方式请分享)。

I found my own solution, the problem was in my Jquery code. Maybe it is not the best way to do it in Entity Framework but this is how I solve this. (If you have a better way please share it).

这里是我全新的代码。

@{
    var format = "dddd, MMMM dd, yyyy"; 
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    int principalId = Model[0].IdNoticia; 
    string principalTitulo = Model[0].Titulo; 
    string principalContenido = Model[0].Contenido;
    DateTime principalFechaDesde = Convert.ToDateTime(Model[0].FeDesde);
    DateTime principalFechaHasta = Convert.ToDateTime(Model[0].FeHasta);
}

<script type="text/javascript">
    function changeDisplay(e) {

        var principalTitulo = $(e).text(); 
        var principalContenido = $(e).siblings(".Contenido:first").val(); 
        var principalId = $(e).siblings(".IdNoticia:first").val(); 
        var principalFechaDesde = $(e).siblings(".FeDesde:first").val();
        var principalFechaHasta = $(e).siblings(".FeHasta:first").val();
        var principalDescripcion = $(e).siblings(".Descripcion:first").val();
        var principalImagen = $(e).siblings(".imgRuta").val();


        $("#currentprincipalTitulo").html(principalTitulo);
        $("#currentprincipalContenido").html(principalContenido);
        $("#currentprincipalId").html(principalId);
        $("#currentprincipalFechaDesde").html(principalFechaDesde);
        $("currentprincipalFechaHasta").html(principalFechaHasta);
        $("#currentprincipalDescripcion").html(principalDescripcion);
        $("#currentprincipalImagen").attr("src", principalImagen);
    }
</script>

<!-- Principal -->
<div class="col-md-12 main">

    <div class="header sec-title-hd">
        <div class="bg-calendar"></div>
        <div class="col-md-7">
            <h5 class="pull-left">NOTICIAS</h5>
            <div>
                <a href="dashboard.html" class="btn sky-blue n-radius-b"> <img src="slider/img/arrow-left.png"> VOLVER</a>
            </div>
        </div>
    </div>

    <div class="content-inter">
        <div class="container-fluid sec-title-hd-sub">
            <div class="row">
                <div class="col-md-7">
                    <div>
                        <figure class="img_N">
                            @foreach (var n in Model) 
                            {
                                var img = n.Noticias2.FirstOrDefault(); 
                                if (img != null && img.Nombre.Equals(@principalId+"_0")) 
                                {
                                    <img id="currentprincipalImagen" src="@img.Ruta@img.Nombre@img.Extension" class="img-responsive" alt="@img.Nombre" />
                                    <figcaption>
                                        <p id="currentprincipalDescripcion">@img.Descripcion</p>
                                    </figcaption>
                                }
                            }
                        </figure>
                    </div>
                    <div class="textnota">
                        <br>
                        <h6 id="currentprincipalId">@principalId</h6>
                        <h5 id="currentprincipalTitulo" class="titulo_N uppercase">@principalTitulo</h5>
                        <p id="currentprincipalFechaDesde" class="time">Desde: @principalFechaDesde.ToString(format)</p> 
                        <p id="currentprincipalFechaHasta" class="time">Hasta: @principalFechaHasta.ToString(format)</p> 
                        <div class="noti_P">
                            <p id="currentprincipalContenido">@principalContenido</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-5">
                    <!-- Right Side -->
                    @foreach (var n in Model)
                    {
                        <!-- Data mostrada -->
                        <blockquote class="blockquote-nopadding bg-calendar-border-left">
                            <p class="time_f">@n.FeDesde.ToString(format)</p>
                            <a href="#" onclick="changeDisplay(this)" class="titulo_N">@n.Titulo</a>
                            <p class="text-justify limit">@n.Contenido</p>

                            <!--Data Enviada al lado Izquierdo-->
                            <input class="IdNoticia" type="hidden" value="@n.IdNoticia" />
                            <input class="Contenido" type="hidden" value="@n.Contenido" />
                            <input class="FeDesde" type="hidden" value="Desde: @n.FeDesde.ToString(format)" />
                            <input class="FeHasta" type="hidden" value="Hasta: @n.FeHasta.ToString(format)" />
                            @foreach (var img in n.Noticias2)
                            {
                                var imgRuta = @img.Ruta + @img.Nombre + @img.Extension;
                                <input class="Descripcion" type="hidden" value="@img.Descripcion" />

                                <input class="imgRuta" type="hidden" value="@imgRuta" />
                            }

                        </blockquote>

                    }
            </div>
        </div>
    </div>
</div>

/ p>

Here the new view,


注意左侧的所有数据都来自id 2。

notice that all the data in the left side are from the id 2.

这篇关于如何通过单击使用EF从右侧更改数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆