razor

Can't get my DropDownListFor to select a selected SelectListItem item in a Dropdown menu

戏子无情 提交于 2019-12-31 02:45:49
问题 I have a collection of items populated to a drop down menu: string myUserName = "PopulatedWithSomeUser"; var users= from x in userRepository.GetAll() select new SelectListItem { Value = x.Id.ToString(), Text = x.Name, Selected = (x.Name == myUserName ) }; This correctly populates an object and sets the selected item. Next I pass this to my View with a ViewModel and try to Populate/select: I tried: @Html.DropDownListFor(model=>model.Users,new SelectList(Model.Users),new {id = "add-user-list",

Ajax.BeginForm results in redirect to partial view instead of in-place

落爺英雄遲暮 提交于 2019-12-31 02:35:13
问题 My Search.cshtml has a div named "search-results" that is to be updated. SearchResults is the action name. I have done this many times on MVC2/VS2008 projects, but this is my first using MVC3 and VS2010. The problem is, instead of my search result being rendered in my div, it clicking submit is redirecting me displaying my partial as a standalone page. I have read that this may be because Ajax is not enabled. My _Layout.cshtml looks like this: <!DOCTYPE html> <html> <head> <title>@ViewBag

Redirect with POST parameters in MVC 4 for Payment Gateway Integration

微笑、不失礼 提交于 2019-12-31 02:24:07
问题 I am trying to do a payment gateway integration using mvc4 in razor. In that i need to call a page with prefilled post form. Using the below method, I am forming the post method form: private static string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form { //Set a name for the form string formID = "PostForm"; //Build the form using the specified data to be posted. StringBuilder strForm = new StringBuilder(); strForm.Append("<form id=\"" + formID + "\" name=\"" +

Render razor view to string without munging the html

孤街醉人 提交于 2019-12-31 01:48:29
问题 I've previously found answers on how to render an MVC 4 view to a string. However, I started using Visual Studio 2013 and now the result is not as expected. See below. <$A$><$B$> <$C$> class="panel"<$D$>> <$E$> class="cover-wrapper"<$F$>> <$G$> href=" <$H$>/book/<$I$><$J$>1<$K$><$L$>/<$M$>"<$N$>><$O$> src="<$P$>http://www. example.com/images/image.jpg<$Q$>"<$R$> class="cover"<$S$> /> <$T$> href="<$U$> <$V$>"<$W$> target="_blank"<$X$> rel="nofollow"<$Y$> class="amazon-button"<$Z$>> <$a$> class

Disabled DropDownList razor mvc

主宰稳场 提交于 2019-12-30 18:33:26
问题 In my razor view, I use a drop down list. I want to have this control disabled (not selectable). My code is: <div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{ @disabled = "disabled" })</div> But it doesn't work, my control is always enabled. Html page code is: <select name="LinguaCodiceMadre" id="LinguaCodiceMadre" data-val-length-max="10" data-val-length="The field LinguaCodiceMadre must be a string with a maximum length of 10." data

ASP.NET MVC 3 using Razor - use conditional expression together with the HTML output

安稳与你 提交于 2019-12-30 18:06:09
问题 I've been bugged with this for many days...(I'm in process of studying ASP.NET MVC 3) In this link -- Razor If/Else conditional operator syntax -- is said that the only valid syntax for conditional expression in Razor engine is @(x?y:z) Alright. Now, how do I write HTML in this conditional expression? I can't use Razor here, following code results in invalid syntax error. @(item.Manager == null ? @:<i>unassigned</i> : item.Manager.Name) After some research I discovered HtmlWriter or Html.Raw

How to display html elements like links in errors rendered via Html.ValidationSummary()

依然范特西╮ 提交于 2019-12-30 10:54:07
问题 One of my error message renders a link. However, Html.ValidationSummary() encodes it and therefore it displays as follow: An account with the mobile or email you have specified already exists. If you have forgotten your password, please <a href="/account/Reset">Reset</a> it. Instead, it should render as: An account with the mobile or email you have specified already exists. If you have forgotten your password, please Reset it. The error is added to the ModelState inside view as follows: if (.

How to use JQuery Datatable.net with ASP.Net 4 Razor and Twitter Bootstrap

落爺英雄遲暮 提交于 2019-12-30 10:26:35
问题 I want to use the jQuery Datatable with ASP.net MVC and Twitter bootstrap. Does anyone have already done this ? 回答1: This may be an old post but I just wanted to add how I got things set up. It seems to be easier than how codea did it above. 1) In your view, simply create your table like normal (with a @foreach or some such thing) and give it an ID of jqueryTable . Then download the following 3 files and put them in the ~/Scripts/ and the ~/Content/ folders: dataTables.bootstrap.css jquery

How to use JQuery Datatable.net with ASP.Net 4 Razor and Twitter Bootstrap

折月煮酒 提交于 2019-12-30 10:26:15
问题 I want to use the jQuery Datatable with ASP.net MVC and Twitter bootstrap. Does anyone have already done this ? 回答1: This may be an old post but I just wanted to add how I got things set up. It seems to be easier than how codea did it above. 1) In your view, simply create your table like normal (with a @foreach or some such thing) and give it an ID of jqueryTable . Then download the following 3 files and put them in the ~/Scripts/ and the ~/Content/ folders: dataTables.bootstrap.css jquery

Html.RenderAction uses Post instead of Get

↘锁芯ラ 提交于 2019-12-30 09:57:07
问题 I have a simple form on my page. When submitted, it checks if ModelState.IsValid and returns the View with the same model if it's not valid. On the same page, I'm rendering an action that contains another form like so: Html.RenderAction("AccountNote", new { id = Model.ID }); Everything works fine until I submit the form on my page and the validation fails. When it shows the page again, the AccountNote action's Post event fires when I'd expect the Get event to fire. I guess it makes sense why