Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > редактирование данных AjaxForms


Автор: Karta 25.1.2013, 02:12
Добрый день,
я пытаюсь сделать форму для редактирования данных. Нашла обучающий урок:
Код

http://ricardocovo.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/

В этом уроке создается сначала лист с данными:
Код

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.Data

{
    public static class CarRepository
    {
        static List<CarModel> CarList;

        static CarRepository() { 
            CarList = new List<CarModel>{
                new CarModel { Id=1, ImageFileName="FordFocusElectric.jpg", Name="Ford Focus Electric", Description = "Great looking car... plus is green."},
                new CarModel { Id=2, ImageFileName="HondaCivic2012.jpg", Name="Honda Civic 2012", Description="You can always count with the Civic"},
                new CarModel { Id=3, ImageFileName="HyundaiHCD12.jpg", Name="Hyundai HCD 12", Description="Can't wait for it to come out!"},
                new CarModel { Id=4, ImageFileName="ToyotaPriusC.jpg", Name="Toyota Prius C", Description="What does the C stands for?"}};
        }

        /// <summary>
        /// NOTE: This is for demostration purposes only. 
        ///         You would normally have your data access layer, either on the web app or in other libraries.
        /// </summary>
        /// <returns></returns>
        public static List<CarModel> GetCars()
        {
            return CarList;
        }
    }
}


а затем отображается этот CarList на страницу :

Код

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Index</h2>
<div id="commonMessage"></div>
<table>
<% foreach (var item in Model) { %>
    <tr>
        <td>
            <img src="/content/images/<%: item.ImageFileName %>" />
        </td>
        <td>
            <strong><span class="carName"><%: item.Name %></span></strong><br />
            <span class="carDescription"><%: item.Description %></span><br /><br />
            <%: Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "editLink" })%>
        </td>
    </tr>  
<% } %>

</table>



Меня интересует как мне вывести на страницу не весь CarList, а только конкретный елемент, например я хочу вывести информацию только для 
Toyota Prius C ?

Спасибо.

Автор: pilotnet 25.1.2013, 07:04
В файле CarsController.cs 
Код

 public class CarsController : Controller
    {
        //
        // GET: /Cars/

        public ActionResult Index()
        {
            List<CarModel> model = CarRepository.GetCars();
            return View(model);
        }



после при получения данных
Код

List<CarModel> model = CarRepository.GetCars();

нужно фильтровать по Name="Toyota Prius C"

Автор: Karta 25.1.2013, 10:59
Я то понимаю, что нужна фильтрация, но как это прописать?
У меня пока не получается....
Может можно сделать фильтрацию на самой стрнаце, что то вроде: item.Name="Toyota Prius C" ???



Код

public ActionResult Index()
        {
            List<CarModel> model = CarRepository.GetCars();
            model.Name = "Toyota Prius C";
            return View(model.Name);
        }


Не работет, может у кого то будут еще какие идеи?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)