我有两个名为_centerDetails.cshtml
和_centerRights.cshtml
的部分视图。
我在点击提交时从centerdetails
传递数据,并希望在切换另一个部分视图时显示此信息,但不将其发布到服务器。
这是我创建的模型类,用于处理我的数据 控制器:
namespace ADWP_AdminWebPortal.Models
{
public class CountryList
{
[Required(ErrorMessage = "Select a Country.")]
public int CountryId { get; set; }
[Required]
public string Country { get; set; }
[Required(ErrorMessage = "Select a State.")]
public int StateId { get; set; }
[Required]
public string State { get; set; }
[Required(ErrorMessage = "Select a City.")]
public int CityId { get; set; }
[Required]
public string City { get; set; }
}
public class CustomerDetails: CountryList
{
public int ClientId { get; set; }
[Required (ErrorMessage="Eneter the First name")]
[DataType(DataType.Text)]
public string FirstName { get; set; }
[Required(ErrorMessage = "Eneter the Middle name")]
[DataType(DataType.Text)]
public string MiddleName { get; set;}
public string NatureOfOccupation { get; set; }
public string AgentId { get; set; }
[Required(ErrorMessage ="Select a Client Type.")]
public string ClientType { get; set; }
public int TariffId { get; set; }
public string TariffName { get; set; }
public int ServiceId { get; set; }
public string ServiceName { get; set; }
public string OrderId { get; set; }
public int PaymentMethodId { get; set; }
public string PaymentMethodName { get; set; }
}
}
在这里你可以看到我创造的混乱。我的问题是当你在同一个控制器中使用多个模型时如何处理多个模型?
这里我没有在一个类中创建所有数据,因为我希望它可以根据我的需要重复使用。
如何处理模型中的数据?这是主要的问题 当我在我的项目中创建部分视图时来找我。
答案 0 :(得分:2)
您可以一起使用CTE和ROW_NUMBER函数删除表中的重复行。
With CTE AS (
SELECT VERIFICATIONTYPE,
NAME,
COST,
RN = ROW_NUMBER() OVER (PARTITION BY VERIFICATIONTYPE, NAME, COST ORDER BY VERFICATIONTYPE)
FROM DETAILS)
DELETE FROM CTE WHERE RN > 1
END
答案 1 :(得分:1)
经过一番努力,我得到了结果。
public class CountryList
{
[Required(ErrorMessage = "Select a Country.")]
public int CountryId { get; set; }
[Required]
public string Country { get; set; }
}
// Added Class
public class State
{
[Required(ErrorMessage = "Select a State.")]
public int StateId { get; set; }
[Required]
public string State { get; set; }
}
// Added Class
public class City
{
[Required(ErrorMessage = "Select a City.")]
public int CityId { get; set; }
[Required]
public string City { get; set; }
}
public class CustomerDetails
{
public int ClientId { get; set; }
[Required (ErrorMessage="Enter the first name")]
[DataType(DataType.Text)]
public string FirstName { get; set; }
[Required(ErrorMessage = "Enter the middle name")]
[DataType(DataType.Text)]
public string MiddleName { get; set; }
public int TariffId { get; set; }
public string TariffName { get; set; }
public int ServiceId { get; set; }
public string ServiceName { get; set; }
public string OrderId { get; set; }
public int PaymentMethodId { get; set; }
public string PaymentMethodName { get; set; }
public List<CountryList> { get; set; } //added list
public List<State> { get; set; } //added list
public List<City> { get; set; } //added list
}
是的,这很容易。