FAQ Database Discussion Community


How Can ignore @ in Pattern in MVC

asp.net-mvc-4
I want write pattern to my textbox in view this textbox will hold email value but i want write RegEx but i received error because RegEx contains @ i wrote @@ but still doesn't work My Code <input type="text" name="Emails" id="Emails" class="form-control Div-heigh" placeholder="To...." required pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" /> ...

mvc 4 custom format validator does not show error and allows the form to submit

asp.net-mvc,validation,asp.net-mvc-4
I have the following validator for a MVC 4 view public class IpFormatValidator: ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ValidationResult resp; if (value != null) { string ip ; IPAddress noUsed ; ip = value.ToString(); if(IPAddress.TryParse(ip, out noUsed)) { resp = ValidationResult.Success; } else { resp...

Saving child entity is not saving the foreign key with entity framework

c#,asp.net-mvc,asp.net-mvc-4
I have the following entities: public class Entidad { [Key] public int Id { get; set; } public string Nombre { get; set; } public virtual ICollection<Propiedad> Propiedades { get; set; } } public class Propiedad { [Key] public int Id { get; set; } public virtual Entidad Entidad {...

Using dropdownlistfor for model with list property

c#,asp.net-mvc,asp.net-mvc-4,model
How do I use dropdownlistfor for this viewmodel? public class ViewModel { public IEnumerable<Model1> model1{ get; set; } } public class Model1 { public string Name { get; set; } public int Id{ get; set; } } How should I do this? @model Models.ViewModels.ViewModel @Html.DropDownListFor(model => model.model1) ...

Prevent page refresh on submit button click

asp.net-mvc-4
I am working in Mvc4. Creating a validation. When I am clicking the submit button and the validation is getting failed and the full page is getting refreshed to display the validation messages. I do not want my page to get refreshed. And another question is is there any way...

Call back from server to client

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I am using ASP.NET MVC 4 application, I need to Display messages in the Client, by sending messages from Controller to Client. My requirement is user click a button in UI and i will process the files on the server and Display message in UI on end of each foreach...

Cannot get data using LINQ in MVC

c#,asp.net-mvc,linq,asp.net-mvc-4
I'm trying to get data in autocomplete from JsonResult Action Method in my controller. I cannot query data with LINQ, I'm sharing code please guide me. Action Method public class VehicleController : Controller { private readonly IService<Vehicle> _service; public VehicleController(IService<Vehicle> service) { _service = service; } public JsonResult AutoComplete(string term)...

MVC - How to render a 'a href' link in a View that's been stored in a database?

asp.net-mvc,asp.net-mvc-4,model-view-controller
Question background: I have an MVC4 app whos homepage data is supplied from a View Model. The Issue: Within the View Model I have a property called AboutUsDescOne This is set from the Controller and Action Method from data that has been retrieved from a database. Within the data set...

MVC HandlerError attribute isn't redirecting to error View on Exception

c#,asp.net-mvc,asp.net-mvc-4
Question Background: I have a simple 'Contact Form' on my page. The user needs to supply their name, email a message subject and the actual message itself. I'm Currently trying to implement an 'Error' View will display during any errors on the mailing process such as an incorrect email format...

ApplicationUser ICollection member not being saved in DB

c#,.net,entity-framework,asp.net-mvc-4,asp.net-mvc-5
I've added some properties to ApplicationUser, and two of them are ICollection's. When I use Update-Database it doesn't generate columns for these two members. So, what am I missing here? I imagine it's very basic. I'm used to working with Hibernate in Java, where it generates a new table for...

Jquery Tabs - return selected tab dynamically

c#,jquery,asp.net-mvc,asp.net-mvc-4,razor
On page load I would like to display selected tab dynamically. This is so validation is displayed for the correct tab. I have the following code: <script type="text/javascript"> $(document).ready(function () { var selectedTabId= $("#SelectedTab").val(); alert(selectedTabId); $('#tabs').tabs( { cache: false, beforeActivate: function (event, ui) { selectedTabId = ui.newPanel.attr('id'); $("#SelectedTab").val(selectedTabId); }, selected:...

Add XElement dynamically using loop in MVC 4?

c#,xml,asp.net-mvc-4,for-loop
i will like to add the Xelement in Xdocument but how can i add in dynamically using loop? I need to capture the user multiple answer and generate the Xelement dynamically. Please guide me or provide any hint. Thanks alot! [HttpPost] public ActionResult SURV_Answer_Submit(List<AnswerQuestionViewModel> viewmodel, int Survey_ID, string Language) {...

Exact need of jquery.validate.js

jquery,asp.net-mvc-4,jquery-validate
I am working in Mvc4. Creating client side validation using jquery. I have created a view. But the validation still working without the validate.js file. May be the uses will be in another way. Can someone please explain me what and how the validate.js file will be used to implement...

access a page in the MVC Global.asax

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I want to redirect to a page in the case that does not accomplish a condition in the global.asax in method application start... redirects to a warning page like this:... protected void Application_Start() { if (MyClass.Warnning == "2") { Response.Redirect("~/warningPage.aspx"); } } but it shows me the following error: response...

Use “Contains” to match part of string in lambda expression

c#,jquery,asp.net-mvc-4,lambda
I have this MVC page where I have three different "input" elements, all the same class, using the jQuery autocomplete. On any one of them I am doing this in the controller: [HttpGet] public ActionResult GetAllItemsEdit(string data, string source) { List<TextValuePair> items = InventoryControlRepository.GetAllItemsTVP(); var result1 = items.Where(item => item.Text.Contains(data.ToUpper())).ToList();...

Why mozilla changes the characters when i use the .net mvc statement redirect?

c#,asp.net-mvc-4,redirect,mozilla
I'm trying to redirect to an external website when everything is done, but firefox changes the http word on the url for a weird set of characters. This is my server side code: [HttpPost] public ActionResult Postular(INFO_BASE_POSTULACION_model pInfoPostulacion) { string rutMD5 = Request["rutMD5"]; int idRegion = Convert.ToInt32(Request["idRegion"]); int idInstrumento =...

Why is my View not displaying value of ViewBag?

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I have a little blog application with posts and tags. This is my model for Post: namespace HelloWorld.Models { public class Post { [Required] [DataType(DataType.Text)] public string Title { get; set; } [Required] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required] [DataType(DataType.DateTime)] public DateTime PostDate { get; set; }...

How to add an Option label on ListBoxFor HTML Helper in ASP.Net MVC

asp.net-mvc,asp.net-mvc-4,html-helper
How can I add an option label like the one existent on the DropDownListFor for a ListBoxFor HTML Helper ? I have the code similar to bellow: <%= Html.ListBoxFor( m => m.SelectedElements, new MultiSelectList(Model.AllPossibleElements, "ID", "Text")) %> And the image bellow is the output: I would like to have a...

Binding data to TextBox without showing text

asp.net,asp.net-mvc,asp.net-mvc-4
When binding text/data to a TextBox, it is done like @Html.TextAreaFor(model=> model.Question) but, when the PostBack happens, the text shows up in the TextBox. Is there a way to still bind the data to the textbox, but not display the text in the textbox? I have a search functionality on...

How to get started with Visual studio 2012

c#,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,visual-studio-2012
I want to create web application using Visual Studio 2012. The application should login into a website and report numerical findings on the UI. The language used will be Visual C#. I have loaded the application and selected on the menu: File> New > Projects. A window appears with multiple...

How to Implement Dependent Dropdownlist in MVC4 Razor and using SQL server also

sql-server,asp.net-mvc-4,razor
I've 2 Dropdownlist called States and Country. but only the States DDL(DropdownList) will be enable the country DDL will be diable. when I select a option in States which is already stored in SQL. The Country DDL Should Show the Selected state's Country automatically from DB. Please help Me..... Ex:If...

How to Upload file onclick of button of type=button not type=submit in mvc4 using html begin form

file,asp.net-mvc-4,button,upload,submit
I have to upload a file using a button (of type button, not submit). And I want to show popup when no-file is selected and clicked on upload, it should not go to controller action. Can anyone help please?...

How to run javascript function in Razor MVC .net

javascript,asp.net-mvc,asp.net-mvc-4,razor
<script type="text/javascript"> @if (@Model.Invoice.InvoiceDate != null) { <text> function UTCToLocalTime(date) { var time = new Date(Date.parse(date)); var timeOffset = -((new Date()).getTimezoneOffset() / 60); time.setHours(d.getHours() + timeOffset); return time; } var date = @Model.Invoice.InvoiceDate UTCToLocalTime(date); </text> } </script> I am printing the above invoice and its open in a window....

Submitting Form in AngularJS and MVC 4

angularjs,asp.net-mvc-4,angularjs-controller,angularjs-factory
I am new to AngulaJS, and I am trying to do as many examples as I can. I found an example online that works pretty well except for the registration part. I tried to register a user; it did not submit the form, and there was not an error message/exception....

MVC Routing News Pages

asp.net-mvc-4,asp.net-mvc-routing
I have managed to get my MVC project to present a list of news items in an SEO friendly manner: /News/ - to present the list /News/NewsItem/id/news-item-title - the individual news item What I would really like is: News/id/news-item-title Exactly how Stackoverflow presents its questions. However, I cant seem to...

How to download a file through ajax request in asp.net MVC 4

jquery,json,asp.net-mvc-4,asp.net-ajax
Below is my code : public ActionResult DownloadAttachment(student st) { var file = db.EmailAttachmentReceived.FirstOrDefault(x => x.LisaId == st.Lisaid); byte[] fileBytes = System.IO.File.ReadAllBytes(file.Filepath); return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.Filename); } This is the script which i'm using $(function () { $("#DownloadAttachment").click(function () { $.ajax( { url: [email protected]("DownloadAttachment", "PostDetail")', contentType: 'application/json; charset=utf-8', datatype: 'json',...

Set JQuery propeties to Image folder path in img src tag

javascript,jquery,html,image,asp.net-mvc-4
Question background: I'm trying to set two propeties of a JQuery function to an img src who's images are stored in the Images folder of my MVC site. The Issue: The following code shows the properties nextText and prevText being set to a left and right .jpg I have in...

Send a parameter from an action to a view

asp.net-mvc,asp.net-mvc-4
I want to send a parameter to a view from an action that resolves and sends that value. The issue is that when the parameter "arrives" to the view, it arrives null giving me an error when I try to manage it. The code I have in the action is...

Delete Confirmation Window

jquery,asp.net-mvc,asp.net-mvc-4,telerik
<div id="modalWindow"> <button id="yes" class="k-button">Yes</button> <button id="no" class="k-button">No</button> </div> <script> var wnd; $(document).ready(function() { wnd = $("#modalWindow").kendoWindow({ title: "Delete confirmation", modal: true, visible: false, resizable: false, width: 300 }).data("kendoWindow"); }); function DeleteItem(e) { e.preventDefault(); var grid = this; var row = $(e.currentTarget).closest("tr"); wnd.center().open(); $("#yes").click(function() { grid.removeRow(row);...

C# entity framework MVC second run error

entity-framework,asp.net-mvc-4,localdb
I am creating db and initializing data with code below, if DB doesnt exist, it creates db and populate it, when I run application second time I get error Cannot drop database "aspnet-app" because it is currently in use. Application_start, with initializations protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes);...

C# Using Bool, how to check a double is truly divisible by another number? [duplicate]

c#,asp.net-mvc-4
This question already has an answer here: How can I calculate divide and modulo for integers 4 answers Is there a way of checking that a value is wholly divisible by another number, for example 1000 divided by 100 would be true, but 1115 divided by 100 would be...

how to forward a link with URI to another link with the same URI

html,asp.net,html5,asp.net-mvc-4,asp.net-web-api-routing
My program directs users to a webpage with their username and password. E.g. http://example.html?username=username&password=password. Now I created another page in asp.net and I want some code on example.html to redirect the link to http://example.aspx?username=username&password=password. So what i want is to get the URI from the first url and direct it...

redirect to actionResult method from an api

c#,asp.net-mvc-4,asp.net-web-api
[HttpPost] public void insertData(string productid) { //insert to db string uri = this.Url.Link("Default", new { controller = "AddProducts", action = "Index" }); //Response.Redirect(Url.Action("", "")); } after inserting to the database i want to redirect to an actionResult method.i have a void method, what do i return it as?...

Need to Close the div in if condition MVC View

asp.net-mvc,asp.net-mvc-4
I am trying to close a div inside the if condition which is inside a foreach loop. @foreach (var item in ViewBag.modal) { counter++; <div class="Class1"> <div class="span6"> <!-- block --> <div class="block"> <div class="block-header"> <div class="left"> @item["Topic"];</div> </div> <div class="collapsein"> @item["Desc"];</div> </div> </div> @if (counter % 2 == 0)...

File upload control in asp.net mvc

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I have written a fileupload control in asp.net mvc.But as of now the logic what i am doing is, i am downloading excel file in to server locally and then processing data and pushing in to oracle database.But some servers due to permission issues , i am not able to...

Return to the same view when no image is selected

asp.net-mvc-4,razor,json.net,entity-framework-5,c#-5.0
I have an upload control. But if the user didnt select an image and the press on the upload button, the user will get an message that he/she has to go back and try again, like this: if (isSavedSuccessfully) { return Redirect(Url.Action("Edit", "Account") + "#tabs-2"); } else { return Json(new...

Partial View's checkbox state not returned to controller

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I have a main view whose Model is of type FacilityViewModel. The main view loads a partial view that also contains a partial view. Both partial views have a model of type FiltersViewModel. The most nested partial view loops through a dictionary and creates a checkbox for each item to...

NHibernate fluent mapping to an entity property

asp.net-mvc-4,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
I have a table called "Customers" and in this table there are store and office address. In the code there is a Customer class with two properties that are of type Address (one for StoreAddress and OfficeAddress). public class Customer { public virtual int Id { get; set;} public virtual...

Jquery: Change contents of