从xml文件在ASP.NET MVC3 razor视图引擎中创建下拉列表。 [英] Creating dropdown list in ASP.NET MVC3 razor view engine from xml file.
问题描述
我正在使用razor视图引擎在ASP.NET MVC3中创建用户注册表单。我正面临着为国家创建下拉列表的问题。国家/地区列表来自xml文件。
我的项目层次结构如下
BusinessLayer - > User_Account - > Account_Registration.cs
这是一个类库,我想在其中创建一个用户注册模型。用户模型的代码如下
Hi,
I am creating a User Registration form in ASP.NET MVC3 using razor view engine. I am facing problem to create a dropdownlist for country. Country list come from xml file.
My project hierarchy is as follows
BusinessLayer -> User_Account -> Account_Registration.cs
This is a class library in which I want to create a Model for user registration. The code for user model is as follows
public class Account_Registration
{
public string User_Name { get; set; }
public string User_EmailID { get; set; }
public string User_Password { get; set; }
public string User_RePassword { get; set; }
public DateTime User_BirthDate { get; set; }
public enum_Gender User_Gender { get; set; }
public string User_Address { get; set; }
public string User_City { get; set; }
public string User_State { get; set; }
public IEnumerable<SelectListItem> User_Country { get; set; }
public string User_WebSite { get; set; }
public string User_Description { get; set; }
}
现在我想知道我应该放置国家XML文件的位置以及如何为XML文件创建下拉列表。 />
我的Xml文件如下
Now I want to know that where I should put country XML file and how can I create dropdownlist for XML file.
My Xml file is as follows
<countries>
<country code="AF" iso="4">Afghanistan</country>
<country code="AL" iso="8">Albania</country>
<country code="DZ" iso="12">Algeria</country>
</countries>
因为我必须在IIS上部署此项目所以我想知道我应该把xml文件放在哪里,以便我可以在类库项目中的Account_Registration模型中访问它,以及如何为人口国家创建下拉列表。
谢谢
As I have to deploy this project on IIS so I want to know where should I put xml file so that I can access it in Account_Registration model which is in class library project and how to create dropdownlist for population countries.
Thanks
推荐答案
您可以在项目的任何位置添加XML文件。只需更改其属性 - >将内容复制到输出目录为始终复制。还要在您正在阅读它的代码中提供XML文件的正确路径。
You can add the XML file in any location within your project. Just change its properties -> Copy content to Output Directory as "Copy Always". Also provide the correct path of the XML file in the code where you are reading it.
这篇关于从xml文件在ASP.NET MVC3 razor视图引擎中创建下拉列表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!