开发者

MVC C# Web application

How do I edit information from an customer settings data model, which doesn't come from a database. I've created a view which starts with

edit.aspx

开发者_StackOverflow<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 

Inherits="System.Web.Mvc.ViewPage" %> Notice it contains MyApp.Models.LocationDisplayOptions. How can I save data on the form, which isn't linked to a database. I'm sorry if this isn't clear, but simply I need to save data not stored in a database.

namespace MyApp.Models
{
    public class LocationDisplayOptions
    {
        public string Town { get; set; }

        public string Country { get; set; }

        public double Latitude { get; set; }

        public double Longitude { get; set; }

        public LocationDisplayOptions()
        { 
            // Some web url stuff 

            Town = dt.Rows[0]["City"].ToString();
            Country = dt.Rows[0]["CountryCode"].ToString();
            Latitude = System.Convert.ToDouble(dt.Rows[0]["Latitude"].ToString());
            Longitude = System.Convert.ToDouble(dt.Rows[0]["Longitude"].ToString());
        }
    }
}


Why do you need to save it? What are you going to do with the data after you save it. That's going to really drive the answer.

If you just need to persist information from one view of the page to another, you can put it in a Session variable.

If you need to persist it longer than that, you could store it in a file on the web server, but if it is a high volume website, that can really slow things down.

You could consider a database. Microsoft SQL CE is a good option for small-footprint data stores, as it doesn't require any server-side installs-- just a DLL that goes along with the rest of your application.

Here's a link to ScottGu's post about SQL CE: http://weblogs.asp.net/scottgu/archive/2010/06/30/new-embedded-database-support-with-asp-net.aspx


Do you merely used drag and drop to work with databases, letting magic happen as far as editing of data is concerned?

While you can exist with LINQ to SQL or EF drag and drop, the "magic" underneath the hood is worthwhile to learn, especially in light of other forms of persistant mechanisms.

To persist to a file, you have to capture the form data and then create a class that handles the save to the file. The best path is to Google saving to the type of file (comma separated, XML, etc) and create the software to handle the persistance of that information. You can test it with a simple console app. When you are happy, use the same pattern to wire to your MVC application. The main difference is you have to get the path from the ASP.NET internals (hard coded == bad).

Someone may have an open source "module" that does this work, so search the open source sites.

Peace and Grace, Greg

Twitter: @gbworld Blog: http://gregorybeamer.wordpress.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜