razor

The ViewData item that has the key 'MaritalStatus' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>' [duplicate]

非 Y 不嫁゛ 提交于 2020-01-05 02:53:31
问题 This question already has answers here : The ViewData item that has the key 'XXX' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>' (6 answers) Closed 3 years ago . I am populating DropDownList from in-memory data and getting this error on POST. Error: The ViewData item that has the key 'MaritalStatus' is of type 'System.String' but must be of type 'IEnumerable'. Controller:- // GET: /Application/Create public ActionResult Create() { List<SelectListItem> lst = new

Format Date with culture in Razor @Html.EditFor

独自空忆成欢 提交于 2020-01-04 21:36:05
问题 MVC 4, C#. In my razor view I have: @Html.EditorFor(model => model.ActionObject.StartDate) Which is annotated in my model with: [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public System.DateTime? StartDate { get; set; } In the view, it is set like so, with date picker: Notice how it is mm/dd/yyyy. How can I change this dynamically based on the user? The user can set there culture to whatever they want. Normally I can do:

html encode/decode - ckeditor

此生再无相见时 提交于 2020-01-04 15:33:51
问题 I am using ckeditor in a cshtml page to input content into my database that will later be displayed on a page with html tags to make the text easier to read. Since I am inputting the content through a textarea, I am getting a an error stating that the html tags that I am inputting <h1><p> are potentially dangerous. To bypass this without turning RequestValidation to false, in my cinfig.js file I have set: config.htmlEncodeOutput = true; I am decoding the data from the database when displaying

How to use Partial Views in ASP.NET MVC?

霸气de小男生 提交于 2020-01-04 15:33:13
问题 I'm building an ASP.NET MVC application and want to use a partial view to display my product-categories. It is going to be a webshop and on each page, below the menubar, I want to show another bar which contains all product-categories. I want to use a partial view for this. Currently in ~/Views/Categories I created the partial view _CategoriesHeader.cshtml . (I did that by selecting "Partial View" on the "Create New View" dialog, so it's actually a partial view) The contents of

How to use Partial Views in ASP.NET MVC?

非 Y 不嫁゛ 提交于 2020-01-04 15:33:10
问题 I'm building an ASP.NET MVC application and want to use a partial view to display my product-categories. It is going to be a webshop and on each page, below the menubar, I want to show another bar which contains all product-categories. I want to use a partial view for this. Currently in ~/Views/Categories I created the partial view _CategoriesHeader.cshtml . (I did that by selecting "Partial View" on the "Create New View" dialog, so it's actually a partial view) The contents of

html encode/decode - ckeditor

做~自己de王妃 提交于 2020-01-04 15:32:33
问题 I am using ckeditor in a cshtml page to input content into my database that will later be displayed on a page with html tags to make the text easier to read. Since I am inputting the content through a textarea, I am getting a an error stating that the html tags that I am inputting <h1><p> are potentially dangerous. To bypass this without turning RequestValidation to false, in my cinfig.js file I have set: config.htmlEncodeOutput = true; I am decoding the data from the database when displaying

Kendo ui Grid shows json instead of grid Asp .net razor

*爱你&永不变心* 提交于 2020-01-04 15:16:27
问题 I trying to initialize my Kendo ui grid. I am able to populate it using the View object, but when I try doing it in Json format (i.e. when moving to next page) I get a screen showing json results instead of my view. Here's the controller code: public class CampaignsController : Controller { // // GET: /Campaigns/ [HttpGet] public ActionResult Index() { return View(GetAllCampaigns()); } public ActionResult Campaigns_Read([DataSourceRequest] DataSourceRequest request) { DataSourceResult result

conversion web form to razor without any error

╄→гoц情女王★ 提交于 2020-01-04 14:35:30
问题 i am trying to convert to razor but showing an error <% AjaxOptions options = new AjaxOptions(); options.HttpMethod = "POST"; %> @AjaxOptions options = new AjaxOptions(); options.HttpMethod = "POST"; 回答1: @{ AjaxOptions options = new AjaxOptions(); options.HttpMethod = "POST"; } 来源: https://stackoverflow.com/questions/22810453/conversion-web-form-to-razor-without-any-error

Invoking a controller's action by button in View without redirecting to any view

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 14:33:31
问题 I wanted to add a button to my ASP .NET MVC WebApplication's view which will invoke a method: public void UpdateDatabase(int personId, int surveyId) { //updating,modifying database } but besides that nothing at all will happen so user will not see any visible changes. The user will not be redirected, visible content of the site will not change, page will not be reloaded. Just like you click a button with no listener associated with it. I have tried <p> @Html.ActionLink("Update database",

Ajax.BeginForm() with checkbox syntax error

偶尔善良 提交于 2020-01-04 12:17:38
问题 I have an Ajax.BeginForm() in a partial view that contains a CheckBox for a bool value. The model is as follows; public class ViewBusinessAdd { [Required(ErrorMessage="Name must be supplied")] [Display(Name = "Business Name")] public string Name { get; set; } [Required(ErrorMessage = "Contact must be supplied")] [Display(Name = "Business Contact")] public string Contact { get; set; } [Display(Name = "Phone Number")] public string Number { get; set; } public string Postcode { get; set; }